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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With