Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Relation between Mulitple instance of EntityManagerFactory
Relation between Mulitple instance of EntityManagerFactory [message #810842] Thu, 01 March 2012 11:00 Go to next message
Kamran Muhammad is currently offline Kamran Muhammad
Messages: 2
Registered: March 2012
Junior Member
Hi Everyone!
I am creating entitymanagerfactory and adding dynamic types to it using JPADynamicHelper class. Types are added successfully.
Now if i go and create a new instance of EntityManagerFactory
with same name and properties . Newly created Factory already has dynamic types earlier added for previous instance of Entity Manager Factory. What is the reason. and what is the relation between multiple instnace of Entity manager factory here.?

Following is the out line of code.

EntityManagerFactory factory = Persistence.createEntityManagerFactory("elink", properties);

List<DynamicType> dynamicTypes = DynamicTypeGenerator
.generateDynamicTypes(classLoader, "edu.model");

JPADynamicHelper helper = new JPADynamicHelper(factory);
helper.addTypes(false, false,dynamicTypes.toArray(new DynamicType[dynamicTypes.size()]));

//now again creating entity manager factory with same name and properties.
EntityManagerFactory factory2 = Persistence.createEntityManagerFactory("elink", properties);
JPADynamicHelper helper2 = new JPADynamicHelper(factory2);
DynamicType type = helper2.getType(dynamicTypes.get(0).getName());
//returned type is not null. This time factory already has dynamic types earlier loaded. Reason why it has those.

Thanks,
Kamran

[Updated on: Thu, 01 March 2012 11:02]

Report message to a moderator

Re: Relation between Mulitple instance of EntityManagerFactory [message #810881 is a reply to message #810842] Thu, 01 March 2012 11:38 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Any factories created with the same persistence unit name and properties will be the same persistence unit.
This allows the same persistence unit accessed in multiple places to be the same persistence unit.

To get a new one, set any of the connection properties, or the "eclipselink.session-name" property to a unique value.


James : Wiki : Book : Blog : Twitter
Re: Relation between Mulitple instance of EntityManagerFactory [message #811599 is a reply to message #810842] Fri, 02 March 2012 10:28 Go to previous messageGo to next message
Kamran Muhammad is currently offline Kamran Muhammad
Messages: 2
Registered: March 2012
Junior Member
Thanks for the reply and help.
So when persistance unit gets recycled. is it the life time of entity manager factory or it is some cache time limit?

Thanks,
Kamran
Re: Relation between Mulitple instance of EntityManagerFactory [message #813724 is a reply to message #811599] Mon, 05 March 2012 11:39 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

When all factories are closed, then the persistence unit is removed.


James : Wiki : Book : Blog : Twitter
Previous Topic:Outer-Joining Subclasses on Queries gives java.sql.SQLException: Too many tables
Next Topic:Oracle11g-HSQLDB
Goto Forum:
  


Current Time: Sat Aug 23 15:58:08 EDT 2014

Powered by FUDForum. Page generated in 0.01667 seconds