Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is transaction management in hibernate?

What is transaction management in hibernate?

in my hibernate application one-to-many mapping is there.

Eg : Student table is mapped with Subjects table.

When I am adding a Student object at that time Subjects table also adding some entry.

While any error occurs in Subjects table insertion I want automatically delete the Student table entry.

Is it possible through transaction management? Else how is it possible?

like image 677
jaleel Avatar asked Jun 22 '11 12:06

jaleel


1 Answers

What you've described is exactly what transactions are for. The idea is that you group database operations into a single transaction and either they're all successful or they all fail. This way your database cannot end up in an intermediate and invalid state.

Transaction management is a vast and often quite complex area and the way in which you configure it depends on your specific application setup.

Since you're only mentioned Hibernate I would recommend that you start by reading this chapter of the documentation. If you are using Spring to demarcate transaction boundaries I would recommend you read this section of their documentation.

It is worth noting that you cannot send SQL to your database outside of a transaction. There is discussion around this here.

like image 144
Alex Barnes Avatar answered Sep 18 '22 12:09

Alex Barnes