有可能吗?我尝试这样做,但它不起作用:
StatelessSession sess = getSessionFactory().openStatelessSession();
sess.beginTransaction();
MessageDetails md = (MessageDetails) sess.get(MessageDetails.class,1189469L);
md.setCc(null);
sess.update(md);
sess.getTransaction().commit();
sess.close();
cc以这种方式定义:
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "MessageEntryCc")
public Set<EmailAndName> getCc() {
return cc;
}
运行代码后,MessageEntryCc仍然包含带有message_details_id = 1189469 ...
的条目答案 0 :(得分:1)
请在映射中添加CascadeType=DELETE_ORPHAN
:
@ManyToMany(fetch = FetchType.LAZY,
cascade={CascadeType.ALL, CascadeType.DELETE_ORPHAN})