You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@olingo.apache.org by "Michael Bolz (JIRA)" <ji...@apache.org> on 2016/06/16 05:41:05 UTC

[jira] [Commented] (OLINGO-971) Issue with Container Managed Persistence in Olingo library V2.0

    [ https://issues.apache.org/jira/browse/OLINGO-971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15333148#comment-15333148 ] 

Michael Bolz commented on OLINGO-971:
-------------------------------------

Hi [~Santosh Kumar],

After a first (quick) look I agree that this is a bug in Olingo and think the (simplest) solution is to prioritise a set EntityManager (over a EntityManagerFactory).
I will check this, create an according patch/commit and give feedback.

Best Regards, Michael

> Issue with Container Managed Persistence in Olingo library V2.0
> ---------------------------------------------------------------
>
>                 Key: OLINGO-971
>                 URL: https://issues.apache.org/jira/browse/OLINGO-971
>             Project: Olingo
>          Issue Type: Bug
>          Components: odata2-jpa
>    Affects Versions: V2 2.0.6
>         Environment: Hana Cloud Platform, JDK 1.7.
>            Reporter: Santosh kumar
>            Assignee: Michael Bolz
>            Priority: Critical
>
> We are working on a Java application that uses Container Managed Persistence in Olingo Odata 2 library.
> Below are the steps we have followed:
> * Defined JTA as transaction type in persistence.xml along with jta-data-source element.
> * Created a custom class JpaServiceFactory that extends Olingo libraries ODataJPAServiceFactory (from olingo-odata2-jpa-processor module).
> * Injected EntityManager into JpaServiceFactory using JNDI lookup( Also defined persistence context in  web.xml using <persistence-context-ref> tag).
> *Note* : we can't use @PersistenceContext to inject Entitymanger beacause JpaServiceFactory is not container managed object.
> * we then set the above EntityManager to oDataJPAContext of ODataJPAServiceFactory.
> *Note* : We are not setting EMF to oDataJPAContext, since, we are using Container managed persistence.
> * When we test the application after these changes, we get *EntityManager not initialized*  exception. Upon investigation we found out that the error is due to the validation check in Olingo class ODataJPAServiceFactory in the method validatePreConditions:
> {code:title=ODataJPAServiceFactory.java|borderStyle=solid}
> private void validatePreConditions() throws ODataJPARuntimeException {
>     if (oDataJPAContext.getEntityManagerFactory() == null) {
>       throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.ENTITY_MANAGER_NOT_INITIALIZED, null);
>     }
> {code}
> * As a mitigation we created a copy of Olingo's ODataJPAServiceFactory class and removed the above method.Modified our JpaServiceFactory class to extend the custom class created of ODataJPAServiceFactory instead of direclty extending ODataJPAServiceFactory.
> * Also we have followed the steps mentioned by Chandan here: [JTA based transactions in JPA processor|https://issues.apache.org/jira/browse/OLINGO-580].
> * After this when tested, we get below exception:
>  bq. java.lang.NullPointerException: while trying to invoke the method javax.persistence.EntityManagerFactory.getMetamodel() of a null object returned from *org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext.getEntityManagerFactory()*at org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmBaseViewImpl.<init>(JPAEdmBaseViewImpl.java:50) at org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmModel.<init>(JPAEdmModel.java:39)
> As we can see from the stack trace above, the library class JPAEdmBaseViewImpl.java again tries to retrieve EntityManagerFactory object which is null for CMP.
> {color:red}
> This is bug in Olingo code. Because, for a Container managed persistence when we set EntityManager in oDataJPAContext, the framework shouldn't throw error for null EMF.
> {color}
> Can anyone look into this issue ?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)