JPA的cascade = REMOVE和Hibernate的@OnDelete一起使用? [英] JPA's cascade = REMOVE and Hibernate's @OnDelete used together?
问题描述
我继承了几乎所有关系都具有以下注释的代码库:
@OneToMany(fetch = FetchType。 LAZY,cascade = {CascadeType.REMOVE},mappedBy =someThing)
@OnDelete(action = OnDeleteAction.CASCADE)
现在我无法理解 @OnDelete
是否首先执行的操作。 Hibernate:OnDelete vs cascade = CascadeType.REMOVE 很有趣,但不幸的是,没有任何答案,并且 @OnDelete
的JavaDoc特别没有价值。
从其他问题看,它看起来像OnDelete注释以某种方式让数据库执行级联,而 并且 假设您有一对一的定向关系 如果你使用CascadeType.REMOVE,那么删除房子也会删除大门。 如果您使用@OnDelete,那么删除大门也会删除房屋。 在这里阅读更多: http://www.ninthavenue.com.au/jpa-cascadetype-remove-vs-hibernate-ondelete I have inherited a code base on which nearly all relations have the following annotations: Now I'm having trouble understanding what From the other questions it looks like the OnDelete annotation somehow lets the DB do the cascading, while the cascading directive on And does Let's say you have a one-to-one directional relationship If you use CascadeType.REMOVE then deleting the house will also delete the door. If you use @OnDelete then deleting the door will also delete the house. Read more here: http://www.ninthavenue.com.au/jpa-cascadetype-remove-vs-hibernate-ondelete 这篇关于JPA的cascade = REMOVE和Hibernate的@OnDelete一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
class House {
@OneToOne
对象门;
@OneToOne(cascade = CascadeType.REMOVE)
对象门;
@OneToOne
@OnDelete(action = OnDeleteAction.CASCADE)
对象门;
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE }, mappedBy = "someThing")
@OnDelete(action = OnDeleteAction.CASCADE)
@OnDelete
does in the first place. Hibernate: OnDelete vs cascade=CascadeType.REMOVE is interesting, but unfortunately doesn't have any answers and the JavaDoc for @OnDelete
is particularly worthless.@OneToMany
let's the ORM do it, but what would ever be the purpose of using them together?@OneToMany
's cascade directive really doesn't allow the ORM implementation to generate a DB based cascade anyway?class House {
@OneToOne
Object door;
}
@OneToOne(cascade=CascadeType.REMOVE)
Object door;
@OneToOne
@OnDelete(action = OnDeleteAction.CASCADE)
Object door;