我尝试用级联“remove”(jpa)和“delete-orphan”映射一对多关系,因为我不希望在保存或保存父母时保存或保存孩子(安全原因由于客户端到服务器(GWT,Gilead))
但是这个配置不起作用。当我尝试使用级联“全部”时,它会运行。为什么 delete-orphan 选项需要级联“all”才能运行?
这是代码(为简单起见,没有 id 或其他字段,类 Thread 定义了一个没有级联的简单多对一属性):removeThread
在事务函数中使用该函数时,它不会运行,但如果我编辑cascade.Remove
成cascade.All
,它会运行.
@Entity
public class Forum
{
private List<ForumThread> threads;
/**
* @return the topics
*/
@OneToMany(mappedBy = "parent", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
public List<ForumThread> getThreads()
{
return threads;
}
/**
* @param topics the topics to set
*/
public void setThreads(List<ForumThread> threads)
{
this.threads = threads;
}
public void addThread(ForumThread thread)
{
getThreads().add(thread);
thread.setParent(this);
}
public void removeThread(ForumThread thread)
{
getThreads().remove(thread);
}
}