Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 325699 - Dynamic JPA: Initialization of the metamodel will fail on FK ID initialization with JPADynamicEntities having to-many relationships
Summary: Dynamic JPA: Initialization of the metamodel will fail on FK ID initializatio...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Michael OBrien CLA
QA Contact:
URL: http://wiki.eclipse.org/EclipseLink/D...
Whiteboard:
Keywords:
Depends on: 266912
Blocks: 325701 325754 297971
  Show dependency tree
 
Reported: 2010-09-19 11:47 EDT by Frank Schwarz CLA
Modified: 2022-06-09 10:08 EDT (History)
3 users (show)

See Also:


Attachments
testcase (5.01 KB, application/x-sdlc)
2010-09-19 12:11 EDT, Frank Schwarz CLA
no flags Details
proposed patch (2.26 KB, patch)
2010-09-19 12:22 EDT, Frank Schwarz CLA
michael.f.obrien: iplog+
Details | Diff
ManagedType must handle member attribute from dynamic JPA via ValuesAccessor subclass of AttributeAccessor (2.62 KB, patch)
2010-11-03 15:51 EDT, Michael OBrien CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Frank Schwarz CLA 2010-09-19 11:47:15 EDT
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
Comment 1 Frank Schwarz CLA 2010-09-19 12:11:26 EDT
Created attachment 179214 [details]
testcase
Comment 2 Frank Schwarz CLA 2010-09-19 12:22:14 EDT
Created attachment 179215 [details]
proposed patch

ManagedTypeImpl#initialize() needs a refactoring
Comment 3 Michael OBrien CLA 2010-09-19 16:03:03 EDT
>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
Comment 4 Michael OBrien CLA 2010-11-03 15:51:50 EDT
Created attachment 182325 [details]
ManagedType must handle member attribute from dynamic JPA via ValuesAccessor subclass of AttributeAccessor
Comment 5 Michael OBrien CLA 2010-11-03 16:33:11 EDT
>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
Comment 6 Michael OBrien CLA 2010-11-03 16:41:04 EDT
>See SVN Rev# 8472 - thank you Frank S.
https://fisheye2.atlassian.com/changelog/eclipselink/?cs=8472
Comment 7 Michael OBrien CLA 2010-11-03 16:41:40 EDT
8472 in 2.2 trunk
Comment 8 Peter Krogh CLA 2010-12-08 14:28:49 EST
ipLog on patch
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:08:03 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink