Hibernate:用继承覆盖sql-delete
我有一个实体 A
和 B extends A
并尝试使用联合继承策略进行软删除。
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@SQLDelete("UPDATE A SET deleted = 1 WHERE id = ?")
A {
@Id long id;
boolean deleted;
}
@Entity
B extends A {}
看来 Hibernate 正确地将表 A
设置为 deleted = 1
,但也删除了表 B
中的整个条目。当然,我想保留这个条目。
对此有什么想法吗?
我正在使用 Hibernate 3.5.5 和基于注释的实体定义。也尝试过 Hibernate 3.6.2。
I have an entity A
and B extends A
and try to have a soft-delete with joined inheritance strategy.
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@SQLDelete("UPDATE A SET deleted = 1 WHERE id = ?")
A {
@Id long id;
boolean deleted;
}
@Entity
B extends A {}
It seems that Hibernate properly sets the table A
to deleted = 1
, but also deletes the whole entry from table B
. I would, of course, like to preserve this entry.
Any ideas on that?
I'm using Hibernate 3.5.5 and annotation-based entity definition. Tried Hibernate 3.6.2 as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要创建一个DeleteEventListener,如下所示:
将其挂接到您的 persistence.xml 中,如下所示
另外,不要忘记更新注释中的级联。
You'd want to create a DeleteEventListener as such:
hook it into your persistence.xml like this
Also, don't forget to update your cascades in your annotations.