Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Resolve PersistenceUnit unitName at runtime
Resolve PersistenceUnit unitName at runtime [message #1657163] Sat, 07 March 2015 21:34 Go to next message
Bill Damage is currently offline Bill DamageFriend
Messages: 5
Registered: February 2015
Junior Member
I currently use

@PersistenceUnit(unitName="foo")
private EntityManagerFactory emf;

And em = emf.createEntityManager(); to get the em instance. Now I need to pass that unitName as a runtime param - how do I go about this please?
Re: Resolve PersistenceUnit unitName at runtime [message #1660946 is a reply to message #1657163] Mon, 09 March 2015 12:06 Go to previous messageGo to next message
Petros Splinakis is currently offline Petros SplinakisFriend
Messages: 12
Registered: September 2014
Junior Member
You may use javax.persistence.Persistence class to retrieve the EntityManagerFactory for the persistence unit you need.
Re: Resolve PersistenceUnit unitName at runtime [message #1671021 is a reply to message #1660946] Fri, 13 March 2015 12:32 Go to previous message
Bill Damage is currently offline Bill DamageFriend
Messages: 5
Registered: February 2015
Junior Member
Thanks!
Used this after removing the @PersistenceUnit annotation and its fine:
emf = Persistence.createEntityManagerFactory("db");
Previous Topic:Ensuring thread safety with JPA entities in Servlets
Next Topic:java.lang.IncompatibleClassChangeError: org/eclipse/persistence/internal/jpa/metadata/accessors/obje
Goto Forum:
  


Current Time: Wed Dec 11 23:30:13 GMT 2024

Powered by FUDForum. Page generated in 0.03232 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top