[ https://issues.apache.org/jira/browse/OPENJPA-2844?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Michael Wiles updated OPENJPA-2844: ----------------------------------- 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... {code:java} public void testGetProperties() { emf.getProperties(); }{code} I get an NPE because _conf in BrokerImpl is not initialised because initialise in this BrokerImpl has not been called. {noformat} 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){noformat} This occurs because the new code for "byPassSynchronizeMappings" mode of initialising the broker does not in fact call initialise... line 280 of EntityManagerFactoryImpl: {code:java} Broker broker = byPassSynchronizeMappings ? conf.newBrokerInstance(user, pass) : _factory.newBroker(user, pass, managed, retainMode, false, cfName, cf2Name);{code} 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. was: 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... {code:java} public void testGetProperties() { emf.getProperties(); }{code} I get an NPE because _conf in BrokerImpl is not initialised because initialise in this BrokerImpl has not been called. {noformat} 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){noformat} This occurs because the new code for "byPassSynchronizeMappings" mode of initialising the broker does not in fact call initialise... line 280 of EntityManagerFactoryImpl: {code:java} Broker broker = byPassSynchronizeMappings ? conf.newBrokerInstance(user, pass) : _factory.newBroker(user, pass, managed, retainMode, false, cfName, cf2Name);{code} 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. > Unable to call getProperties on EnitityManagerFactory before > createEntityManager is called. > ------------------------------------------------------------------------------------------- > > Key: OPENJPA-2844 > URL: https://issues.apache.org/jira/browse/OPENJPA-2844 > Project: OpenJPA > Issue Type: Bug > Components: kernel > Affects Versions: 3.1.3 > Reporter: Michael Wiles > Priority: Major > > 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... > {code:java} > public void testGetProperties() { > emf.getProperties(); > }{code} > I get an NPE because _conf in BrokerImpl is not initialised because > initialise in this BrokerImpl has not been called. > {noformat} > 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){noformat} > This occurs because the new code for "byPassSynchronizeMappings" mode of > initialising the broker does not in fact call initialise... > line 280 of EntityManagerFactoryImpl: > {code:java} > Broker broker = byPassSynchronizeMappings ? > conf.newBrokerInstance(user, pass) : > _factory.newBroker(user, pass, managed, retainMode, false, cfName, > cf2Name);{code} > 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. > > -- This message was sent by Atlassian Jira (v8.3.4#803005)