保存具有OneToMany关系的模型
|
你好
我有这样的模型:
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
我不明白该错误消息,因为如果列表以前为空,则该错误消息会出现。
没有找到相关结果
已邀请:
1 个回复
倪蕊悲潍
然后在您的控制器中: