【发布时间】:2011-05-16 07:50:27
【问题描述】:
嗨 我有这样的模型:
public class Person extends Model {
...
@OneToMany(orphanRemoval = true, mappedBy = "person")
@Cascade({ CascadeType.ALL })
public List<Contact> infos = new ArrayList<Contact>();
}
public class Contact extends Model {
...
@ManyToOne(optional = false)
public Person person;
}
我的控制器中有这样一个方法:
public static void savePerson(Person person) {
person.save();
renderJSON(person);
}
我的问题是,当我尝试使用 savePerson() 保存一个人时出现此错误(仅当我的 Person 列表不为空时):
PersistenceException occured : org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: models.Person.infos
我不理解错误消息,因为如果列表之前是否为空,它就会出现。
【问题讨论】:
-
不行,因为我无法应用本文中的解决方案
标签: hibernate jpa playframework one-to-many