Skip to Content

How to use Olingo with JTA

Hi all,

I'm going through the SAP HANA Cloud End-to-End-Development Scenarios and need some help on how to use Olingo + JPA.

The tutorial shows how to use Resource Local Persistence Units with Olingo.

I'd like to use JTA (and therefore Container Managed Transactions) with Olingo.

For instance, it would be great to inject an EntityManager into the

PersonsListServiceFactory, which extends ODataJPAServiceFactory

could that be done (e.g. through CDI)?

Thanks, regards

Vincenzo

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2013 at 11:44 AM

    Hi Vincenzo,

    yes, this is supported in 2.x runtime. You just need to specify the persistence unit e.g.

    ...

    <persistence-unit name="xxxx" transaction-type="JTA">

    <jta-data-source>jdbc/DefaultDB</jta-data-source>
    ...

    Best regards

    Xu

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Vincenzo,

      Happy New Year! 😊

      I finally found some time to look at this in more details and I am happy to report that it works as expected (so it's not affected by the issue from ). Actually, it's rather simple. I am attaching a sample project demonstrating it. The key points are:

      • in MyServlet we inject a Printer POJO:
      @Inject Printer printer;
      
      • in the Printer POJO we inject the following:
      @Inject @Informal Greeting greeting;
      @Resource UserTransaction ut;
      @PersistenceContext EntityManager em;
      • note also the empty beans.xml in WEB-INF.


      That's it. 😉 Feel free to play around with the project. (After unzipping, you have to rename testcdi.txt to testcdi.zip and unzip again.)


      Hope it helps!

      --Vlado

      testcdi.txt.zip (9.0 kB)

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.