Seam hibernate删除孤儿问题
我使用一个实体 Employee ,在我的方法中定义了一个 UserMaster 列表,
public class EmployeeMaster{
private String employee_id;
private String first_name;
private String last_name;
private List<UserMaster> userMaster = new ArrayList<UserMaster>();
@OneToMany(fetch = FetchType.LAZY, mappedBy = "employeeMaster")
@Cascade(value = {CascadeType.SAVE_UPDATE,CascadeType.DELETE_ORPHAN})
public List<UserMaster> getUserMaster() {
return userMaster;
}
public void setUserMaster(List<UserMaster> userMaster) {
this.userMaster = userMaster;
}
}
我调用
xsession.saveOrUpdate(employeeMaster);
这里,我显式清除以前的子集合并添加新的子对象,
但是删除孤儿在这里不起作用.. 仅插入查询正在运行请帮助
带有cascade=“all-delete-orphan”的集合 不再被拥有实体引用
控制台中显示消息
Im using an entity Employee and inside that a list of UserMaster is defined
public class EmployeeMaster{
private String employee_id;
private String first_name;
private String last_name;
private List<UserMaster> userMaster = new ArrayList<UserMaster>();
@OneToMany(fetch = FetchType.LAZY, mappedBy = "employeeMaster")
@Cascade(value = {CascadeType.SAVE_UPDATE,CascadeType.DELETE_ORPHAN})
public List<UserMaster> getUserMaster() {
return userMaster;
}
public void setUserMaster(List<UserMaster> userMaster) {
this.userMaster = userMaster;
}
}
in my method im calling
xsession.saveOrUpdate(employeeMaster);
Here im clearing previous child collection explicitly and add new Child objects
But the delete orphan is not working here ..
Only the insert query is running Pls Help
A collection with cascade="all-delete-orphan"
was no longer referenced by the owning entity
message is showing in the console
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您用
setUserMaster()
替换了加载实体中包含的集合。当集合配置为
DELETE_ORPHAN
时,您无法通过这种方式替换集合,您需要使用其自己的方法修改现有集合。It looks like you replaced the collection contained in the loaded entity with
setUserMaster()
.When collection is configured with
DELETE_ORPHAN
, you cannot replace the collection this way, you need to modify the existing collection using its own methods.