Uploaded image for project: 'Olingo'
  1. Olingo
  2. OLINGO-971

Issue with Container Managed Persistence in Olingo library V2.0

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • V2 2.0.6
    • V2 2.0.8
    • odata2-jpa
    • None
    • Hana Cloud Platform, JDK 1.7.
    • Important

    Description

      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:
        ODataJPAServiceFactory.java
        private void validatePreConditions() throws ODataJPARuntimeException {
            if (oDataJPAContext.getEntityManagerFactory() == null) {
              throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.ENTITY_MANAGER_NOT_INITIALIZED, null);
            }
        
      • 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.
      • After this when tested, we get below exception:

        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.

        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.

      Can anyone look into this issue ?

      Attachments

        Issue Links

          Activity

            People

              mirbo mibo
              Santosh Kumar Santosh kumar
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: