Community
Participate
Working Groups
>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)
Created attachment 140867 [details] javaClass set on custom descriptor later on MetamodelImpl.initialize()
>See rev# 4614 http://fisheye2.atlassian.com/changelog/eclipselink/?cs=4614 >New tests in MetamodelMetamodelTest.java http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelMetamodelTest.java?r1=4587&r2=4614
Mass update to change fixed in target.
>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.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink