This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Reverting changes on objects after a database rollback Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Reverting changes on objects after a database rollback" Watch "Reverting changes on objects after a database rollback" New topic
Author

Reverting changes on objects after a database rollback

Germano Bax
Greenhorn

Joined: Sep 04, 2010
Posts: 3
Hi,
I have one specific object that is persisted in two tables of the database. The database contains internationalized data, so one table, say TABLE_X, keeps the non-internationalized data (references to other tables, and some numbers), and the other, say TABLE_X_DETAILS keeps the internationalized (mainly descriptions in different languages).

I have a java class, say CLASS_X, which must be persisted. When I persist some instance of CLASS_X, I must perform 2 inserts: one on TABLE_X, and other insert on TABLE_X_DETAILS. TABLE_X has a generated primary key. I have a DAO class that performs the task.

Before the database inserts, the instance of CLASS_X have a null id. When the insert on TABLE_X is performed, I get the generated primary key, then I use it to insert the localized details on TABLE_X_DETAILS, and if all goes well, I set the generated id on the object.

My insert method looks like this:



The issue here is that the insert method may called as part of bigger transactions that performs many other changes. If one of those transactions fails, I need to remove the generated id on the objects. Is there a way to identify that a transaction was rolled back and clean up the changes I performed on the objects? I was looking for some kind of transaction listener, but found nothing that could help me here. I would like to have something like the below (I invented below example just to make my point):




Is there anything I can use to implement that bevahiour? I'm using spring JDBCTemplate but could not find anything related.
Thanks and regards,
Bax
 
 
subject: Reverting changes on objects after a database rollback
 
Similar Threads
retrieve autonumber value of last insert
hibernate and DB triggers
setAutoCommit()
Passed SCBCD 5.0 :)
Transactions not rolling back