Skip to main content


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 JosicFriend
Messages: 2
Registered: July 2013
Junior Member
Hi,
Is it good idea to have always open EnityManager during application life? Does it consume some resources like database connection or memory for entities?

Thanks

Zlaja
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 DelahuntFriend
Messages: 1389
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,
Chris
Previous Topic:Birt with JBOSS 5 Issue
Next Topic:Mapping Oracle NUMBER type to Java Type Options
Goto Forum:
  


Current Time: Tue Apr 23 08:12:45 GMT 2024

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

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

Back to the top