Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Update on a long property lost during a transaction with find with pessimistic read lock
icon5.gif  Update on a long property lost during a transaction with find with pessimistic read lock [message #728471] Fri, 23 September 2011 10:26 Go to next message
dimo.velev is currently offline dimo.velevFriend
Messages: 13
Registered: August 2011
Junior Member
Hi,

I have a very strange behavior which is either a bug or due to my misunderstanding of the API guarantees of JPA2. I am using eclipselink 2.3.0 over JPA2 and basically have an entity which stores a Long identifier. I have a DAO that returns this identifier and increments it. The code works with parallel transactions and if executed sequentially in separate transactions but *fails* when executed in the same transaction. The code looks like this:
begin transaction (the unit test)
for (int i=1; i<10; i++) {
  Identifier identifier = entityManager.find(Identifier.class, domain, LockModeType.PESSIMISTIC_READ);
  long result = identifier.getLastId();
  identifier.setLastId(result+1);
  System.out.println(identifier + " with RESULT=" + result);
}
commit transaction (done by the unit test)


This code prints the same value every time:
Identifier@2aa2f9e6 with RESULT=1
Identifier@2aa2f9e6 with RESULT=1
...
Identifier@2aa2f9e6 with RESULT=1


If I move the transaction boundaries in the cycle everything works fine. The query seems to return the same (identically the same if we trust the default Object implementation of toString()) entity every time but the value of the lastId field gets reset to the original value as read from the database the first time.

Any ideas what I might be doing wrong?

Best regards
Dimo
Re: Update on a long property lost during a transaction with find with pessimistic read lock [message #728530 is a reply to message #728471] Fri, 23 September 2011 12:38 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
The object is not flushed to the database until commit, so my guess is that the pessimistic read lock is causing a refresh. Try putting a flush in the for loop and file a bug if that works.

Best Regards,
Chris
Re: Update on a long property lost during a transaction with find with pessimistic read lock [message #728531 is a reply to message #728471] Fri, 23 September 2011 12:39 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
No Message Body

[Updated on: Fri, 23 September 2011 12:40]

Report message to a moderator

Re: Update on a long property lost during a transaction with find with pessimistic read lock [message #728657 is a reply to message #728530] Fri, 23 September 2011 15:39 Go to previous message
dimo.velev is currently offline dimo.velevFriend
Messages: 13
Registered: August 2011
Junior Member
Hi Chris,
thank you for the response. yes, that is my current workaround and it works. i will file a bug as soon as i get back home.
Best regards,
Dimo
Re: Update on a long property lost during a transaction with find with pessimistic read lock [message #728660 is a reply to message #728530] Fri, 23 September 2011 15:39 Go to previous message
dimo.velev is currently offline dimo.velevFriend
Messages: 13
Registered: August 2011
Junior Member
Hi Chris,
thank you for the response. yes, that is my current workaround and it works. i will file a bug as soon as i get back home.
Best regards,
Dimo
Previous Topic:(no subject)
Next Topic:EclipseLink and Log4j
Goto Forum:
  


Current Time: Fri Mar 29 06:25:21 GMT 2024

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

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

Back to the top