Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 366952

Summary: Cannot use Criteria API when creating EntityManagerFactory with an existing ServerSession
Product: z_Archived Reporter: Ilyes Ben Hassen <ilyes_bh>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P2 CC: tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Ilyes Ben Hassen CLA 2011-12-16 10:49:48 EST
Build Identifier: 

According to the Eclipselink javadoc it is possible to create an EntityManagerFactory with a ServerSession.
The EntityManager created is able to execute JPQL but not Criteria API.

see following code snippt:

ServerSession serverSession = EclipselinkService.getInstance().getServerSession()
	EntityManagerFactory entityManagerFactory = JpaHelper.createEntityManagerFactory(serverSession);
	EntityManager entityManager = entityManagerFactory.createEntityManager();
	CriteriaBuilder cb = entityManager.getCriteriaBuilder();
			
Following exception is thrown since setupImpl is null:

java.lang.NullPointerException at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getMetamodel(EntityManagerFactoryDelegate.java:592)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getCriteriaBuilder(EntityManagerFactoryDelegate.java:566)
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.getCriteriaBuilder(EntityManagerImpl.java:2287)

Note: Our data model is created automatically, so it hard to use JPA annotation or XML mapping, we create however owr own org.eclipse.persistence.sessions.Project and therefore a ServerSession.
How can we reuse these objects to construct a full-feature EntityManagerFactory?

Reproducible: Always
Comment 1 Tom Ware CLA 2012-01-23 10:41:26 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 2 Eclipse Webmaster CLA 2022-06-09 10:27:08 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink