0

In EclipseLink 2.5.2, how can I obtain the instance of the org.eclipse.persistence.sessions.Project class that is associated with my existing PersistenceUnit / EntityManagerFactory so that I can call setDefaultQueryResultsCachePolicy?

Thanks.

XDR
  • 4,070
  • 3
  • 30
  • 54

1 Answers1

0

You can get it from Session, and you can get Session from EntityManager.

// EntityManagerImpl is from package org.eclipse.persistence.internal.jpa
Session session = ((EntityManagerImpl) entityManager).getActiveSession();
Project project = session.getProject();
Predrag Maric
  • 23,938
  • 5
  • 52
  • 68
  • You might want to add a session customizer to your persistence unit properties so that the session is changed only once, upfront, before it is initialized: https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Customizers This allows you to make mapping and other changes to the session and project – Chris Nov 26 '14 at 19:44