Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2844

Unable to call getProperties on EnitityManagerFactory before createEntityManager is called.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.2.0
    • None
    • kernel
    • None

    Description

      It seems that with OPENJPA-2834 I can no longer call getProperties on EntityManagerFactory without calling createEntityManager first. AFAICT createEntityManager calls the "other" path and actually does initalise the BrokerImpl.

      If I add the following to the TestGetProperty in persistence-jdbc...

          public void testGetProperties() {
              emf.getProperties();    
          }

       I get an NPE because _conf in BrokerImpl is not initialised because initialise in this BrokerImpl has not been called.

      java.lang.NullPointerException at org.apache.openjpa.kernel.BrokerImpl.getProperties(BrokerImpl.java:792) at 
      org.apache.openjpa.kernel.DelegatingBroker.getProperties(DelegatingBroker.java:228) at 
      org.apache.openjpa.persistence.EntityManagerImpl.getProperties(EntityManagerImpl.java:1967) at 
      org.apache.openjpa.persistence.EntityManagerFactoryImpl.doCreateEM(EntityManagerFactoryImpl.java:300) at 
      org.apache.openjpa.persistence.EntityManagerFactoryImpl.getProperties(EntityManagerFactoryImpl.java:122) at 
      org.apache.openjpa.conf.TestGetProperty.testGetProperties(TestGetProperty.java:48) at 
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at 
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at 
      java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at 
      java.base/java.lang.reflect.Method.invoke(Method.java:566) at junit.framework.TestCase.runTest(TestCase.java:176) at 
      junit.framework.TestCase.runBare(TestCase.java:141)

      This occurs because the new code for "byPassSynchronizeMappings" mode of initialising the broker does not in fact call initialise...

      line 280 of EntityManagerFactoryImpl:

      Broker broker = byPassSynchronizeMappings ?
       conf.newBrokerInstance(user, pass) :
       _factory.newBroker(user, pass, managed, retainMode, false, cfName, cf2Name);

       That conf.newBrokerInstance does not call initialise on the broker so the _conf field in BrokerImpl is null - thus the NPE when calling getProperties.

      I'm not sure if this is expected behaviour or not in this context.

      I picked up the issue when running with Spring and Spring data - this depends on the ability to successfully call getProperties before an entity manager has been created. The reality is chances are other contexts also depend on this ability.

      Though maybe what could be possible is to allow the _conf in BrokerImpl to be null? OPENJPA-2834 was done to address an issue with startup time as far as I can tell, and if we add the initialise to the new path maybe that startup time work will be undone? 

       

      What sweetens the pot somewhat is that the _conf reference in BrokerImpl points to is the JDBCConfigurationImpl which is already present in the EntityManagerFactoryImpl... 

      I can see that running the newBroker function on the _factory is the long startup option so that would not be a solution. 

      Problem is that the doCreateEM method actually calls em.getProperties in line 300 - this call fails as the BrokerImpl.getProperties fails. 

      Attachments

        Activity

          People

            Unassigned Unassigned
            michaelwiles Michael Wiles
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: