Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Shared cache returning same object (identity) to different sessions?
Shared cache returning same object (identity) to different sessions? [message #817557] Sat, 10 March 2012 08:33 Go to next message
Davy Herben is currently offline Davy HerbenFriend
Messages: 1
Registered: March 2012
Junior Member
Hi all,

I'm building a JEE6 application with eclipselink JPA2 on glassfish 3.1.1, and I'm puzzled by some behaviour I'm seeing that seems to be related to the shared session cache.

The application, for now, is a simple crud application for a list of Product entities. All is going fine with one user, but when testing with multiple users, I noticed that changes to a Product by user A were immediately visible to user B, even though user A had not committed anything yet, and nothing was written to the database.

After a lot of debugging, I found out that both users, from their respective EntityManagers, were receiving the exact same object, which of course explains the behaviour I've seen. After completely disabling the shared cache, the problem went away, but so did the performance of the application.

Is it normal that the EclipseLink shared cache is returning the same object to different users? I could see how this could make sense for objects that are marked as read-only. You're not supposed to change those, so it would not hurt to share object identity among user sessions. But I cannot see this making any sense for read-write objects. That probably means I'm either doing or thinking something wrong.

I do want Product instances to be cached in the shared cache, no need to go to the database every time. I would expect the cache to return me a clone of the cached object though, not the cached object itself.

In case it matters: the application is following Adam Bien's Gateway pattern: the entities are retrieved from an EXTENDED EntityManager, and not inside a transaction. A transaction is only started to commit the changes. This keeps the objects attached across user requests. I've been thinking that maybe the nontransactional loading makes EclipseLink consider the entities as read-only?

Any help or insight would be much appreciated.

Davy




Re: Shared cache returning same object (identity) to different sessions? [message #825183 is a reply to message #817557] Tue, 20 March 2012 15:23 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

EclipseLink only shares read-only objects. Something it wrong with your application.

Either you are incorrectly sharing the same EntityManager across users, or somehow corrupting your object model.
Try a simple test of select the same objects from different EntityManagers, they should be different. Try to isolate when you get shared objects. It may be related to your usage of merge() or detached objects, or you may be storing references to objects it your app, and sharing them amongst different users. Also check if you are using property access and have side effects in your get/set methods.




James : Wiki : Book : Blog : Twitter
Previous Topic:Customizing JPA entity generation
Next Topic:@OrderBy problem
Goto Forum:
  


Current Time: Sun Nov 23 03:49:42 GMT 2014

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

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