0

可能吗?我尝试这样做,但它不起作用:

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 的条目...

4

1 回答 1

1

CascadeType=DELETE_ORPHAN在您的映射中添加:

  @ManyToMany(fetch = FetchType.LAZY, 
                      cascade={CascadeType.ALL, CascadeType.DELETE_ORPHAN})
于 2012-12-05T13:45:33.547 回答