• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

em.refresh required?!

 
Jesse van Houten
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've got a big application which uses @version tags for the optimistic locking.

The thing i'm getting is that in transaction1 a version gets incremented.
- This is also done in the db
- This returns correctly if i do a entityManager.find
- This returns correctly if i do a entityManager.createQuery with simple eql.

But in transaction2, the version is set back when i retrieve the object from the enitity manager (still correct in the database though).

At first i suspected a rollback, that seemed most logical, but it doesnt appear so, since some weird things get me to retrieve the correct version as well.

Let me explain with some pseudo code.








I think i'm doing something else wrong, but the refresh is the only (non-hardcoded) way of getting the real version of the child in the entityManager.

It appears that my parent is in the enitity manager with a old version of child. And when the parent is retrieved, it's old reference of child overwrites the updated (post-transaction1) version of child?

Am i supposed to use refresh, or is something else going wrong?

Regards,

Jesse van Houten
[ August 21, 2008: Message edited by: Jesse van Houten ]
 
Scott Selikoff
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like transaction 1 is not committed when transaction 2 is executed (since its throwing an optimistic locking error), have you tried forcing the commit in transaction 1?

Also keep in mind many EJB/J2EE server implementations are beta-ish and filled with unfixed bugs, what software are you using? You might want to consider taking a look at the source code for the server (if its available) to understand what's going on behind the scenes.
 
Jesse van Houten
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but if the changes are not commited, how come the Entity manager still remembers them?

Remember that if i do a direct find on the child, before i do a find on the parent, the child IS correct. Just not if i call the parent first.

It's as if when i call the parent, it has the outdated version of the child, and it replaces the updated one in the entitymanager?!


Btw: Using glassfish v2
[ August 22, 2008: Message edited by: Jesse van Houten ]
 
Jerwin Louise Uy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you considered cascading the update from the parent's point of view?

Instead of merging the state of the child, merge the state of the parent.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic