Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clarification on Java Transaction for update and select on same record in same transaction

 
javah passion
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Folks,

Could someone please clarify on the following:

In my Code:

Step 1: Begin Transaction T1

Step 2: Issue UPDATE DML SQL on a record R1 in method save(Record record). I update a value on this record say date.
This update modifies the Date field from Jan 1, 2013 gets modified to Aug 1, 2013 and

Step 3: Read the same record R1 using SELECT in method getLatestData(String recordID). (WHAT WILL THE CODE READ ? Jan 1, 2013 or Aug 1, 2013 ?)

Step 4: COMMIT | Rollback

Step 5: End Transaction T1


What data will Step 3 Read when the Step2 issues an UPDATE on the Record R1 on the table in the Database ? Will it read Jan 1, 2013 or Aug 1, 2013.

All these steps happen in same transaction, its not 2 transactions, but 1 transaction.

All help is appreciated!!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will read August because that's what was written. Note that this only applies to JDBC. If you are using a technology that caches queries, behavior can vary.

When you get two multiple transactions, I recommend reading about transaction isolation levels
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic