I have inherited a code base on which nearly all relations have the following annotations:
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE }, mappedBy = "someThing")
@OnDelete(action = OnDeleteAction.CASCADE)
Now I'm having trouble understanding what @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.
From the other questions it looks like the OnDelete annotation somehow lets the DB do the cascading, while the cascading directive on @OneToMany
let's the ORM do it, but what would ever be the purpose of using them together?
And does @OneToMany
's cascade directive really doesn't allow the ORM implementation to generate a DB based cascade anyway?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…