Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Opened EntityManager
Opened EntityManager [message #1066263] Mon, 01 July 2013 18:47 Go to next message
Zlatko Josic is currently offline Zlatko Josic
Messages: 2
Registered: July 2013
Junior Member
Is it good idea to have always open EnityManager during application life? Does it consume some resources like database connection or memory for entities?


Re: Opened EntityManager [message #1066467 is a reply to message #1066263] Tue, 02 July 2013 18:44 Go to previous message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1035
Registered: July 2009
Senior Member
EntityManagers seem to have been designed to be short lived much like a transaction. As such, they have their own cache (different from a shared cache) to maintain references to managed entities, and are not thread safe. While EclipseLink uses weak references by default (configurable through the ReferenceMode property), which allows untouched Entities to be garbage collected, using a single long lived EM for reading can still use large amounts of memory if care is not taken to detach entities before changing them - every query on that EM will see the uncommitted modifications otherwise. Changes made in other EntityManagers do not get reflected in Entities already loaded in the long lived EM unless it is cleared, so most apps generally find it easier to just obtain EMs as needed and close them when done rather than clearing them. Clear can also cause problems with triggering lazy relationships, as the relationship is resolved using the EM that loaded the entity.

Best Regards,
Previous Topic:Eclipselink - JPA 2.0 - Select with lockMode and maxResult doesn't work
Next Topic:Mapping Oracle NUMBER type to Java Type Options
Goto Forum:

Current Time: Fri Oct 31 05:55:13 GMT 2014

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

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