hibernate中的事务管理是什么?
hibernate中的事务管理是什么?
在我的休眠应用程序中存在一对多映射。
例如:Student
表与Subjects
表映射。
当我添加一个 Student
对象时,Subjects
表也添加了一些条目。
当 Subjects
表插入中发生任何错误时,我想自动删除 Student
表条目。
可以通过事务管理吗?不然怎么可能呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所描述的正是交易的目的。这个想法是将数据库操作分组到单个事务中,它们要么全部成功,要么全部失败。这样您的数据库就不会处于中间和无效状态。
事务管理是一个广阔且通常相当复杂的领域,配置它的方式取决于您的特定应用程序设置。
由于您只提到了 Hibernate,因此我建议您首先阅读 文档的这一章。如果您使用 Spring 来划分事务边界,我建议您阅读 this他们的文档的 部分。
值得注意的是,您无法在事务之外将 SQL 发送到数据库。 此处对此进行了讨论。
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.