休眠:OnDelete 与级联 = CascadeType.REMOVE [英] Hibernate: OnDelete vs cascade=CascadeType.REMOVE
问题描述
@OnDelete(action=OnDeleteAction.CASCADE)
和 cascade=CascadeType.REMOVE
我在这里阅读:是否有 OnDelete 的等效注释在 JPA2使用 @OnDelete(action=OnDeleteAction.CASCADE)
级联将由 DB 处理,而使用 cascade=CascadeType.REMOVE
级联将由 ORM 处理(休眠).
I read here: Is there an equivalent annotation for OnDelete in JPA2
that with @OnDelete(action=OnDeleteAction.CASCADE)
the cascade will be handled by the DB, while with cascade=CascadeType.REMOVE
the cascade will be handled by the ORM (Hibernate).
您能解释一下 Hibernate 处理与 DB 处理之间的区别吗?数据库"是如何做到的?
另外,我想知道我为什么要关心差异.我的意思是,我为什么要选择一种态度而不是另一种态度.
Also, I would like to know why should I care about the difference. I mean, why should I choose one attitude over the other.
最后一个问题是,查看 OnDelete javadoc 我想知道为什么它没有说明是什么以及为什么我应该使用它(顺便说一句,继承路径在哪里?).那么这些要点记录在哪里?
Last question is, looking at the OnDelete javadoc I was wondering why it says nothing about what is does and why I should use it (BTW where is the inheritance path?). So where are these points documented?
推荐答案
1-有些数据库支持级联选项,有些数据库不支持:如果数据库支持级联,那么 hibernate 将相应地创建模式并让数据库处理级联.
1-Some database support cascade option and some databases do not :If the database support cascade then hibernate will create schema accordingly and let database to handle cascading.
2-如果数据库句柄级联使用它,其他副hibernate必须查询数据库,这是性能损失.
2-If database handle cascade use it ,other vice hibernate have to query database and this is a performance lost.
3-不知道
这篇关于休眠:OnDelete 与级联 = CascadeType.REMOVE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!