[
https://issues.apache.org/jira/browse/OLINGO-971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15333372#comment-15333372
]
Santosh kumar commented on OLINGO-971:
--------------------------------------
Hi [~mirbo],
Thanks for the update.
I forgot to metion one more point, since, EntityManager is not thread safe
unless it is injected into a stateless EJB or something similar. I'm thinking
Olingo will have to provide a mechanism to handle concurrent transactions
similar to stateless EJB or an explicit locking mechanism might be required
(i.e. whereever em.persist() is invoked in the Olingo library we might need
locking as mentioned in the JPA 2.1 specification for Locking and Concurrency).
Let me know what you think ?
Thanks and Regards,
Santosh
> 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)