AW: [eclipselink-users] When are Entities Equal?
Thanks for your Answer!
Currently I use a stateful architecture. Why should it be a Problem if user sessions live to long? As the EntityManager only holds a connection in specific cases, this should not waste much resources.
With a long-living EntityManager I the entities that it has registered may become out of date, yes, but this also happens to the data in second-level cache, so using a new EntityManager can also return stale objects.
Isn't there a bennefit from using only one EntityManager per user session, that for each user session equal objects are not stored multiple times in memory?
To the use of VPD:
Is there currently a (nearly) pure JPA-way of using proxy authentification ? I have found Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=224964 which sounds very nice, will that be included in the 1.0 release?
Another feature for easier use of VPD would be the possibility to supply user credentials via the properties map in the createEntityManager(..) method (like openjpa does) and return an exclusive connection for each EntityManger.
Many thanks for your answer, best regards,
----- Ursprüngliche Mail ----
Von: James Sutherland <jamesssss@xxxxxxxxx>
Gesendet: Montag, den 28. April 2008, 15:03:05 Uhr
Betreff: Re: AW: [eclipselink-users] When are Entities Equal?
In general I would recommend you create a new EntityManager per server
request, or per transaction.
If you are using a JEE managed EntityManager one is automatically created
per transaction, or per operation outside a transaction.
I suppose it is related to having a stateful architecture or a stateless
architecture. If you have a stateless architecture than you would create a
new EntityManager per request. If you have a stateful architecture that you
could create one per user session, but be careful of user sessions living
In general the cost of creating an EntityManager is pretty minimal, and the
main concern with a long lived EntityManager is that the entities that it
has registered may become out of date.
In EclipseLink an EntityManager only holds a connections from the pool in a
transaction after a flush or write, or if an exclusive connection policy is
> I have a question about when to work with the same EntityManager and when
> to close it and get a new one.
> The JPA examples I found where quite different, sometimes the
> EntityManager is created and used the whole time in the example, and
> sometimes for each query a new EntityManager is created (like in the
> TopLink Essentials examples
> An EntityManager is not threadsafe, ok, but what if I use it sequentially?
> For example:
> If I have a Web Application is it better to create an EntityManager for
> every User Session (there wont be many), reuse it for every read operation
> and only create other EntityManager if I need to read something
> simultaneously, or is it better to create/close an EntityManager in every
> read/write method?
> Thanks in advance, best regards,
> Alex Schaefer
> -------- Original-Nachricht --------
>> Datum: Tue, 15 Apr 2008 20:14:32 -0400
>> Von: Gordon Yorke <gordon.yorke@xxxxxxxxxx>
>> An: EclipseLink User Discussions <eclipselink-users@xxxxxxxxxxx>
>> Betreff: Re: [eclipselink-users] When are Entities Equal?
>> Hello Tim,
>> Yes, as long as you continue to work within the same EntityManager
>> without clearing then only one instance of any object will exist within
>> that EntityManager/persistence context. em.find(Employee.class,
>> managerId) == department.getManager(). Unless you are in an Application
>> Server you control when the EntityManager is closed or cleared.
>> Container managed transactional entity managers will get switched at the
>> end of the transaction. Once you call clear or act on a different
>> EntityManager then the instances from the old EntityManager will not be
>> the same instances as retrieved from the new EntityManager.
>> Tim Hollosy wrote:
>> > I've got an entity with a many to one, let's call it employees, with a
>> > department.
>> > So my employee entity has a Department field.
>> > If I'm in the same Entity Manager and I do a find on an Employee to
>> > get an instance of a specific Employee Entity, then later in the same
>> > EM I do a select all on departments, my list of departments now
>> > contains a reference to the same Department that my Employee entity
>> > references.
>> > This is really great for doing things like databinding on drop down
>> > lists, because I can bind the list of departments directly to the
>> > department on my employee entity.
>> > However, is this safe? Can I count on these being the _same_ entities;
>> > not just entities with the same field values all the time? What's
>> > eclipselink doing behind the scenes?
>> > Thanks,
>> > Tim
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
EclipseLink , http://www.oracle.com/technology/products/ias/toplink/
Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink ,
Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
View this message in context: http://www.nabble.com/AW%3A-When-are-Entities-Equal--tp16873274p16938487.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.
eclipselink-users mailing list
Lesen Sie Ihre E-Mails jetzt einfach von unterwegs.