You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@olingo.apache.org by "Cherian, Stephen" <st...@sap.com> on 2014/09/01 16:05:51 UTC

Injecting Entity Manager to Olingo with JTA

Hi Olingo team,
  We were planning to use Apache Olingo  Java libraries(1.2.0) for developing a Java based on SAP HANA Cloud. We were planning to use  JPA with container managed persistence for this application. We were wondering how to inject Entity Manager to class which extends ODataJPAServiceFactory as mentioned http://olingo.apache.org/doc/tutorials/CreateWebApp.html for container managed persistence .  I came across an SCN thread regarding Injecting Entity Manager to Olingo with JTA http://scn.sap.com/thread/3463636 . Unfortunately as per the person who started the thread he does not have a solution yet. Can you give some sample code or guidance on how we can achieve Container Managed Persistence with Olingo.

Thanks and Best Regards
Stephen

Re: Injecting Entity Manager to Olingo with JTA

Posted by "Bolz, Michael" <mi...@sap.com>.
Hi Stephen,

I think this is possible.
You have to extend the "ODataJPAServiceFactory" and initialize the
"ODataJPAContext" with the via JEE generated Entity Manager Factory.
Code snippet:

    ODataJPAContext oDataJPAContext = getODataJPAContext();
    EntityManagerFactory emf =
Persistence.createEntityManagerFactory(persistenceName);
    oDataJPAContext.setEntityManagerFactory(emf);
    oDataJPAContext.setPersistenceUnitName(PUNIT_NAME);

An example can be found in the "JPAReferenceServiceFactory" within the
JPA-Processor-Ref-Web module.


Another very good contact person for the JPA-Processor is Chandan.
He has the best knowledge in this context.
@Chandan: Perhaps you can add here also some helpful comments  ;o)

Kind regards,
Michael



On 02.09.14 08:38, "Cherian, Stephen" <st...@sap.com> wrote:

>Hi Michael,
>  Thanks for your inputs. We will use v 2.0.0.   We would like to use the
>auto generation features with the JPA-Processor if it can be achieved
>with CMP.
>
>Best Regards
>Stephen
>
>-----Original Message-----
>From: Bolz, Michael [mailto:michael.bolz@sap.com]
>Sent: 02 September 2014 11:40
>To: dev@olingo.apache.org
>Subject: Re: Injecting Entity Manager to Olingo with JTA
>
>* PGP - S/MIME Signed by an unverified key: 02-09-2014 at 11:40:28
>
>Hi Stephen,
>
>Nice to here that you want to use Apache Olingo.
>But my first suggestion is to use Olingo in version "2.0.0" (instead of
>1.2.0).
>Version 2.0.0 includes several fixes, improvements and is the current
>stable version for OData Version 2.
>
>Now to your question, do you want to use the auto generation features
>which the JPA-Processor (ODataJPAServiceFactory) provides (e.g. EDM based
>on JPA annotated model)?
>Or do you want to create an own implementation of an
>"ODataSingleProcessor" which then uses an Entity Manager (with CMP)?
>
>Kind regards,
>Michael 
>
>
>
>
>On 01.09.14 16:05, "Cherian, Stephen" <st...@sap.com> wrote:
>
>>Hi Olingo team,
>>  We were planning to use Apache Olingo  Java libraries(1.2.0) for
>>developing a Java based on SAP HANA Cloud. We were planning to use  JPA
>>with container managed persistence for this application. We were
>>wondering how to inject Entity Manager to class which extends
>>ODataJPAServiceFactory as mentioned
>>http://olingo.apache.org/doc/tutorials/CreateWebApp.html for container
>>managed persistence .  I came across an SCN thread regarding Injecting
>>Entity Manager to Olingo with JTA http://scn.sap.com/thread/3463636 .
>>Unfortunately as per the person who started the thread he does not have a
>>solution yet. Can you give some sample code or guidance on how we can
>>achieve Container Managed Persistence with Olingo.
>>
>>Thanks and Best Regards
>>Stephen
>
>* D046871 <mi...@sap.com>
>* Issuer: SAP-AG - Unverified

Re: Injecting Entity Manager to Olingo with JTA

Posted by "Bolz, Michael" <mi...@sap.com>.
Hi Stephen,

Nice to here that you want to use Apache Olingo.
But my first suggestion is to use Olingo in version "2.0.0" (instead of
1.2.0).
Version 2.0.0 includes several fixes, improvements and is the current
stable version for OData Version 2.

Now to your question, do you want to use the auto generation features
which the JPA-Processor (ODataJPAServiceFactory) provides (e.g. EDM based
on JPA annotated model)?
Or do you want to create an own implementation of an
"ODataSingleProcessor" which then uses an Entity Manager (with CMP)?

Kind regards,
Michael 




On 01.09.14 16:05, "Cherian, Stephen" <st...@sap.com> wrote:

>Hi Olingo team,
>  We were planning to use Apache Olingo  Java libraries(1.2.0) for
>developing a Java based on SAP HANA Cloud. We were planning to use  JPA
>with container managed persistence for this application. We were
>wondering how to inject Entity Manager to class which extends
>ODataJPAServiceFactory as mentioned
>http://olingo.apache.org/doc/tutorials/CreateWebApp.html for container
>managed persistence .  I came across an SCN thread regarding Injecting
>Entity Manager to Olingo with JTA http://scn.sap.com/thread/3463636 .
>Unfortunately as per the person who started the thread he does not have a
>solution yet. Can you give some sample code or guidance on how we can
>achieve Container Managed Persistence with Olingo.
>
>Thanks and Best Regards
>Stephen