This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 282518 - JPA: Metamodel superType requires javaClass set on custom descriptor on MappedSuperclassAccessor
Summary: JPA: Metamodel superType requires javaClass set on custom descriptor on Mappe...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL: http://wiki.eclipse.org/EclipseLink/D...
Whiteboard:
Keywords:
Depends on:
Blocks: 266912 297928 303063 322585
  Show dependency tree
 
Reported: 2009-07-06 09:45 EDT by Michael OBrien CLA
Modified: 2022-06-09 10:22 EDT (History)
1 user (show)

See Also:


Attachments
javaClass set on custom descriptor later on MetamodelImpl.initialize() (7.46 KB, patch)
2009-07-06 09:56 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 Michael OBrien CLA 2009-07-06 09:45:49 EDT
>Issue: javaClass not set on my custom RelationalDescriptor for MappedSuperclassAccessor
This causes issues later setting up the ManagedType superType heiarchy on IdentifiableType because a lookup based on descriptor javaClass only finds null.

relationalDescriptor	RelationalDescriptor  (id=112)	
	javaClass	null	
	javaClassName	"org.eclipse.persistence.testing.models.jpa.metamodel.Corporation" (id=115)	

>Later when I am processing supertype for the IdentifiableType mappedSuperclassType - the javaClass is null - preventing a lookup on supertype
mappedSuperclassType	MappedSuperclassTypeImpl<X>  (id=403)	
	descriptor	RelationalDescriptor  (id=334)	
	javaClass	null	
	members	HashMap<K,V>  (id=411)	
	metamodel	MetamodelImpl  (id=364)	
	supertype	null	


>Solution: JPA 1.0 or JPA 2.0 impl fix
The javaClass must be set on our descriptor using the appropriate classloader.
This can either be done during metadata or metamodel processing.
1) If set during metadata processing in MetadataProject.addMappedSuperclassAccessor():464 then we end up invoking a __persistence_new() call on the descriptor - something we do not want for MappedSuperclass descriptors.
    relationalDescriptor.convertClassNamesToClasses(getPersistenceUnitInfo().getClassLoader());
causes ...
java.lang.NoSuchMethodError: org.eclipse.persistence.testing.models.jpa.metamodel.Person.<init>(Lorg/eclipse/persistence/internal/descriptors/PersistenceObject;)V
	at org.eclipse.persistence.testing.models.jpa.metamodel.User.<init>(User.java)
	at org.eclipse.persistence.testing.models.jpa.metamodel.User._persistence_new(User.java)
	at org.eclipse.persistence.internal.descriptors.PersistenceObjectInstantiationPolicy.buildNewInstance(PersistenceObjectInstantiationPolicy.java:30)
	at org.eclipse.persistence.descriptors.ClassDescriptor.selfValidationAfterInitialization(ClassDescriptor.java:3473)
	at org.eclipse.persistence.descriptors.ClassDescriptor.validateAfterInitialization(ClassDescriptor.java:5201)
	at org.eclipse.persistence.descriptors.ClassDescriptor.postInitialize(ClassDescriptor.java:3210)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:463)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:669)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)


2) The better approach will be to set the java Class later during metamodel processing in MetamodelImpl.initialize():163
    descriptor.convertClassNamesToClasses(this.getSession().getActiveSession().getClass().getClassLoader());


See the attached patch for both the unused MetadataProject and the in-use MetamodelImpl change.

After discussing this with Guy we will use the following function call to get the Class from the className for the correct classLoader.

ClassDescriptor.convertClassNamesToClasses(classLoader)
Comment 1 Michael OBrien CLA 2009-07-06 09:56:29 EDT
Created attachment 140867 [details]
javaClass set on custom descriptor later on MetamodelImpl.initialize()
Comment 3 Peter Krogh CLA 2009-08-26 09:56:34 EDT
Mass update to change fixed in target.
Comment 4 Peter Krogh CLA 2009-08-26 09:59:03 EDT
Mass update to change fixed in target.
Comment 5 Peter Krogh CLA 2009-08-26 10:04:43 EDT
Mass update to change fixed in target.
Comment 6 Peter Krogh CLA 2009-08-26 10:06:34 EDT
Mass update to change fixed in target.
Comment 7 Michael OBrien CLA 2010-09-03 15:20:55 EDT
>See the fix for bug # 322585 in SVN rev# 8141 for 2.2 and 8142 for 2.1.2
https://fisheye2.atlassian.com/changelog/eclipselink/?cs=8141
We now do a preemptive DB login via getServerSession to force initializeDescriptors so that a MappedSuperclass javaClass is set on the descriptor when a client does an emf.getMetamodel() or emf.getCriteriaBuilder() before at least one EntityManager is created or logged in.
Comment 8 Eclipse Webmaster CLA 2022-06-09 10:22:16 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink