File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transaction over multiple tables

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you maintain a Transaction over multiple Table inserts? I will be entering data into Table1 and retrieving the ID then entering that ID and other data into Table2 then possibly a 3rd Table. (Normalization, ha).
If any one of those inserts fail for any reason, I don't want any of them to happen. And I just didn't know if you could maintain a Transaction that would roll back inserts into multiple tables.
Thanks.
 
Jason Steele
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg,

Man, I don't think I've ever seen you stumped in here! And truth be told, I'm not sure I got the correct answer, but here it goes. I believe, and feel free to chime-in whenever, that once a transaction has begun and full rollback can be performed anytime to the last commit. Now if that is not correct, somebody please correct me. I would certainly like to know.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Man, I don't think I've ever seen you stumped in here
You just haven't been around long enough.
I think, and this goes along with your thinking, that if I begin a transaction for 1 table and if there are no errors then I can go into a transaction for a second table, and then if there are no errors, I can commit both transactions at the end of the task.
This makes sense to me, but I will have to see. Now with that being said, I am beginning to use Hibernate for my project so I don't even know if this applies. But it will be good to know for future reference anyway.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can perform multiple inserts in a single transaction. This is pretty much the whole purposes of transactions: to make sure that the database retains relational integrity.
bear
 
Dana Hanna
Ranch Hand
Posts: 227
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:
Man, I don't think I've ever seen you stumped in here
You just haven't been around long enough.
I think, and this goes along with your thinking, that if I begin a transaction for 1 table and if there are no errors then I can go into a transaction for a second table, and then if there are no errors, I can commit both transactions at the end of the task.
This makes sense to me, but I will have to see. Now with that being said, I am beginning to use Hibernate for my project so I don't even know if this applies. But it will be good to know for future reference anyway.


A transaction is not begun on a table, it is begun on a connection. Anything that the connection does (with some limits ex. TRUNCATE), will be rolled back with a rollback call.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic