Community
Participate
Working Groups
Build Identifier: Trunk If a JPADynamicEntity has a one-to-many-relationship, the initialization of the JPA2 metamodel fails with: java.lang.NullPointerException at org.eclipse.persistence.internal.jpa.metamodel.IdentifiableTypeImpl.initializeIdAttributes(IdentifiableTypeImpl.java:96) at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.initialize(MetamodelImpl.java:440) at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.<init>(MetamodelImpl.java:109) at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.<init>(MetamodelImpl.java:128) at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.getMetamodel(EntityManagerSetupImpl.java:2011) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getMetamodel(EntityManagerFactoryImpl.java:511) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getCriteriaBuilder(EntityManagerFactoryImpl.java:485) at user.test.bug309039.VirtualModelTest.queryCriteria(VirtualModelTest.java:100) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Reproducible: Always Steps to Reproduce: A test case will be provided shortly
Created attachment 179214 [details] testcase
Created attachment 179215 [details] proposed patch ManagedTypeImpl#initialize() needs a refactoring
>Initially, I see no NPE (this is before we could compile the following parameterized generic in a recent Dynamic API change) >However, this is because we are hiding the NPE which is visible during debugging only //Class<? extends DynamicEntity> employeeClass = helper.getType("Employee").getJavaClass(); Class employeeClass = helper.getType("Employee").getJavaClass(); [EL Finest]: 2010-09-19 15:19:56.004--ServerSession(12122157)--Thread(Thread[main,5,main])--Begin predeploying Persistence Unit virtualmodel; session file:/C:/wse/w35e/user.test.325699/bin/_virtualmodel_url=jdbc:derby://127.0.0.1:1527/weblogic;create=true_user=APP; state Initial; factoryCount 0 [EL Finest]: 2010-09-19 15:19:56.129--ServerSession(12122157)--Thread(Thread[main,5,main])--End predeploying Persistence Unit virtualmodel; session file:/C:/wse/w35e/user.test.325699/bin/_virtualmodel_url=jdbc:derby://127.0.0.1:1527/weblogic;create=true_user=APP; state Predeployed; factoryCount 1 [EL Finest]: 2010-09-19 15:19:56.144--ServerSession(12122157)--Thread(Thread[main,5,main])--Begin deploying Persistence Unit virtualmodel; session file:/C:/wse/w35e/user.test.325699/bin/_virtualmodel_url=jdbc:derby://127.0.0.1:1527/weblogic;create=true_user=APP; state Predeployed; factoryCount 1 [EL Info]: 2010-09-19 15:19:58.047--ServerSession(12122157)--Thread(Thread[main,5,main])--file:/C:/wse/w35e/user.test.325699/bin/_virtualmodel_url=jdbc:derby://127.0.0.1:1527/weblogic;create=true_user=APP login successful >However we do get an ignored exception in our catch-all that we should look at [EL Finest]: 2010-09-19 15:19:58.235--ServerSession(12122157)--Thread(Thread[main,5,main])--Initialization of the metamodel failed during deployment. Ignoring exception: [null] [EL Finest]: 2010-09-19 15:19:58.406--UnitOfWork(6131844)--Thread(Thread[main,5,main])--PERSIST operation called on: {Employee}. [EL Finest]: 2010-09-19 15:19:58.406--UnitOfWork(6131844)--Thread(Thread[main,5,main])--PERSIST operation called on: {Address}. [EL Finer]: 2010-09-19 15:19:58.406--UnitOfWork(6131844)--Thread(Thread[main,5,main])--begin unit of work commit [EL Finer]: 2010-09-19 15:19:58.422--ClientSession(4171180)--Connection(9800632)--Thread(Thread[main,5,main])--begin transaction [EL Finest]: 2010-09-19 15:19:58.422--UnitOfWork(6131844)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery({Employee 67d93a32-ec56-45b3-a1d9-ae24cb39c8b1}) [EL Fine]: 2010-09-19 15:19:58.422--ClientSession(4171180)--Connection(9800632)--Thread(Thread[main,5,main])--INSERT INTO EMPLOYEE (ID, NAME) VALUES (?, ?) bind => [67d93a32-ec56-45b3-a1d9-ae24cb39c8b1, John Doe] [EL Finest]: 2010-09-19 15:19:58.437--UnitOfWork(6131844)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery({Address f1e2fc62-eb04-4488-a5b3-49896d0651dd}) [EL Fine]: 2010-09-19 15:19:58.437--ClientSession(4171180)--Connection(9800632)--Thread(Thread[main,5,main])--INSERT INTO ADDRESS (ID, CITY) VALUES (?, ?) bind => [f1e2fc62-eb04-4488-a5b3-49896d0651dd, Pleasantville] [EL Finest]: 2010-09-19 15:19:58.437--UnitOfWork(6131844)--Thread(Thread[main,5,main])--Execute query DataModifyQuery() [EL Fine]: 2010-09-19 15:19:58.453--ClientSession(4171180)--Connection(9800632)--Thread(Thread[main,5,main])--UPDATE ADDRESS SET EMPLOYEE_ID = ? WHERE (ID = ?) bind => [67d93a32-ec56-45b3-a1d9-ae24cb39c8b1, f1e2fc62-eb04-4488-a5b3-49896d0651dd] [EL Finer]: 2010-09-19 15:19:58.656--ClientSession(4171180)--Connection(9800632)--Thread(Thread[main,5,main])--commit transaction [EL Finest]: 2010-09-19 15:19:59.28--ServerSession(12122157)--Thread(Thread[main,5,main])--Begin undeploying Persistence Unit virtualmodel; session file:/C:/wse/w35e/user.test.325699/bin/_virtualmodel_url=jdbc:derby://127.0.0.1:1527/weblogic;create=true_user=APP; state Deployed; factoryCount 1 >After an update to 8216 >I agree that initialize should be refactored, a slightly modified patch will be uploaded shortly that includes extra refactoring. >I see that the member field has not been initialized mapping UnidirectionalOneToManyMapping (id=151) attributeName "addresses" (id=161) member null >And after when we process Id's we assume Id attributes are set Thread [main] (Suspended (breakpoint at line 96 in IdentifiableTypeImpl)) EntityTypeImpl<X>(IdentifiableTypeImpl<X>).initializeIdAttributes() line: 96 MetamodelImpl.initialize() line: 440 MetamodelImpl.<init>(DatabaseSession) line: 109 MetamodelImpl.<init>(EntityManagerSetupImpl) line: 128 EntityManagerSetupImpl.getMetamodel() line: 2011 EntityManagerSetupImpl.deploy(ClassLoader, Map) line: 408 EntityManagerFactoryImpl.getServerSession() line: 164 JpaHelper.getServerSession(EntityManagerFactory) line: 161 VirtualModelTest.initializeEMF() line: 59 >The catchall exception handler is not printing out the real exception session.log(SessionLog.FINEST, SessionLog.METAMODEL, "metamodel_init_failed", new Object[]{e.getMessage()}); [EL Finest]: 2010-09-19 15:47:51.197--ServerSession(4347715)--Thread(Thread[main,5,main])--Initialization of the metamodel failed during deployment. Ignoring exception: [null] >Good fix on checking for the alternate class ValuesAccessor - the Id attribute of type List is getting picked up now. attribute ListAttributeImpl<X,V> (id=146) elementType EntityTypeImpl<X> (id=152) managedType EntityTypeImpl<X> (id=116) mapping UnidirectionalOneToManyMapping (id=122) addTargetQuery DataModifyQuery (id=137) attributeAccessor ValuesAccessor (id=140) attributeName "addresses" (id=143) >in Thread [main] (Suspended (breakpoint at line 96 in IdentifiableTypeImpl)) EntityTypeImpl<X>(IdentifiableTypeImpl<X>).initializeIdAttributes() line: 96 MetamodelImpl.initialize() line: 440 MetamodelImpl.<init>(DatabaseSession) line: 109 MetamodelImpl.<init>(EntityManagerSetupImpl) line: 128 EntityManagerSetupImpl.getMetamodel() line: 2011 EntityManagerSetupImpl.deploy(ClassLoader, Map) line: 408 EntityManagerFactoryImpl.getServerSession() line: 164 JpaHelper.getServerSession(EntityManagerFactory) line: 161 VirtualModelTest.initializeEMF() line: 59
Created attachment 182325 [details] ManagedType must handle member attribute from dynamic JPA via ValuesAccessor subclass of AttributeAccessor
>variant (error) testing with forced null member [EL Finest]: 2010-11-03 15:44:22.811--Thread(Thread[Thread-3,6,main])--The java Member is null for the Attribute [declaredCenterStringField] with managedType [MappedSuperclassTypeImpl@25631337:MS_MS_Entity_Center [ javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.MS_MS_Entity_Center descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.MS_MS_Entity_Center --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)]), mappings: 2]] and descriptor [RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.MS_MS_Entity_Center --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)])]. [EL Finer]: 2010-11-03 15:46:40.939--DatabaseSessionImpl(5452358)--Thread(Thread[Thread-3,6,main])--Begin MetamodelMetamodelTest [EL Finer]: 2010-11-03 15:46:41.22--DatabaseSessionImpl(5452358)--Thread(Thread[Thread-3,6,main])--Finished MetamodelMetamodelTest >TEST MODEL NAME: (JUnit test): MetamodelMetamodelTest Errors: (failures): 0 Fatal Errors: (errors): 0 Passed: 135 Total Tests: 135 >TEST MODEL NAME: (JUnit test): Criteria Errors: (failures): 0 Fatal Errors: (errors): 0 Passed: 142 Total Tests: 142 >LRG AllCMP3TestRunModel 2169 0 0 1984.462 2010-11-03T19:53:03 xps435
>See SVN Rev# 8472 - thank you Frank S. https://fisheye2.atlassian.com/changelog/eclipselink/?cs=8472
8472 in 2.2 trunk
ipLog on patch
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink