Community
Participate
Working Groups
Example: EntityManagerFactory emf = Persistence.createEntityManagerFactory("employee"); emf.getMetamodel(); If you caus ethe underlying server session to be created and initialized then this succeeds.
Setting target and priority. See the following page for a description of the meanings of these values: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
FYI, the problem is because RelationalDescriptor has javaClassName set but not javaClass. One fix might be to override javaClass to lookup the class by name and set it if its not set.
Note: The solution here is not as simple as getting the javaClass from the className. The step in login that allows this to work is descriptor initialization - all descriptors must be initialized to allow our model generation to work.
Just found out this can be really annoying, because if you have an EJB that calls getCriteriaBuilder BEFORE any database connection (like its going to query the database), then you get an NPE
>This issue is a duplicate of bug 322585 and is related to bug 297928 - an entityManagerFactory.getMetamodel() is invalid before at least one entityManager.deploy() - a refactor so that we can use the metamdoel on the EMF before creating an entityManager is being designed for bug 322585 in DI 106 http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_106:_20100810:_322585:Metamodel_initialization_via_EMF.getMetamodel.28.29_before_EM_deploy_results_in_an_invalid_Metamodel_because_of_UNINITIALIZED_descriptor.initializationStage - Currently metamodel initialization is split into 2 parts (emf.predeploy() and em.deploy()
>This work will be done in bug # 322585 *** This bug has been marked as a duplicate of bug 322585 ***
>Fix Summary/Workaround Essentially this fix in bug # 322585 just makes validation default to true unless disabled - validation is off by default - login during emf predeploy is now on by default >workaround is to enable validation in persistence.xml The following property is named as though the persistence unit is "only" used for validation. In fact it validates the persistence unit by doing a deploy just after the predeploy - without waiting for client code to login - after that it behaves normally. This solves our issue where we may get a NPE on an unitialized descriptor's javaClass (was null) set on a Metamodel ManagedType <property name="eclipselink.validation-only" value="True"/>
>Also note that by running getServerSession() or login() via deploy() in the predeploy() we get the proper classLoader - we cannot just call getClassForClassName() - as we need to wait until we have the real classLoader not the JEE temporary classLoader
Created attachment 178166 [details] Option 7 (in use): Do a getServerSession that does a deploy/login that calls initializeDescriptors only for early emf.getMetamodel() users - em.getMetamodel() users do not login
>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. If a NullPointerException occurs on early post-predeploy but pre-deploy access to the Metamodel via an EntityManagerFactory.getMetamodel() or emf.getCriteriaBuilder() call before an initial login to the DB - then reopen this bug. NPE in ManagedTypeImpl.getTypeClassFromAttributeOrMethodLevelAccessor NPE in MetamodelImpl.initialize
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink