views:

54

answers:

2

hi the find method does not return the latest version of an object. somewhere in my code I find an object, change it, merge it and commit my changes. In the database the changes are made but in another function I find this object and my changes are not there. I've checked race-conditions with the result that there are no race-conditions. I've checked if there are duplicates of this object or different ids but that works fine.

Does anyone have an idea?

db: mysql persistence: eclipselink

+1  A: 

Do you have an EntityManager already open while another EntityManager does the merge/commit? The stale entity might be coming from an EntityManager that is not yet sync'ed with the changes committed to the database in another EntityManager elsewhere.

Try calling the flush() method on the EntityManager that needs to be sync'ed.

Jim Tough
ahh, I see, thanks jim.
heimschmiede
@heimschmiede Answer edited...
Jim Tough
A: 

jim is right. I've got two EntittyManager which are out of sync. My solution is now to have only one entity-manager. Is there a nice solution to get both manager synced because I have two threads and it can be possible that both threads wants to begin a transaction at the same time for instance which might be a problem...

heimschmiede