You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Richard Zowalla (Jira)" <ji...@apache.org> on 2021/06/11 07:10:00 UTC
[jira] [Comment Edited] (OPENJPA-2844) Unable to call getProperties
on EnitityManagerFactory before createEntityManager is called.
[ https://issues.apache.org/jira/browse/OPENJPA-2844?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17361474#comment-17361474 ]
Richard Zowalla edited comment on OPENJPA-2844 at 6/11/21, 7:09 AM:
--------------------------------------------------------------------
We are seeing the same issue as described above in [ReloadableEntityManagerFactoryTest.java |https://github.com/apache/tomee/blob/66de40e24e9f6ffff14c69a6b7acf91759ccccaa/container/openejb-core/src/test/java/org/apache/openejb/persistence/ReloadableEntityManagerFactoryTest.java]in TomEE after the OpenJPA 3.2.0 upgrade.
was (Author: rzo1):
We are seeing the same issue as described above in one [test|[https://github.com/apache/tomee/blob/66de40e24e9f6ffff14c69a6b7acf91759ccccaa/container/openejb-core/src/test/java/org/apache/openejb/persistence/ReloadableEntityManagerFactoryTest.java]] in TomEE after the OpenJPA 3.2.0 upgrade.
> 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.2.0
> 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. 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.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)