我尝试使用 JPA 和 GAE 持久化一个包含预定义实例(实体)的实例(实体),关系是 oneToOne,如下所示:
@Entity class Address{ ... @OneToOne(cascade = CascadeType.ALL)private City city;}
@Entity class City{...}
我创建了城市实例(实体)并将其持久化,效果很好,当尝试创建包含创建的城市实例的地址实例时(因为从 UI 中,它从下拉框中选择),我得到以下异常:
javax.persistence.PersistenceException: Detected attempt to establish Address(no-id-yet) as the parent of City(20) but the entity identified by City(20) has already been persisted without a parent. A parent cannot be established or changed once an object has been persisted.
是否应该使用任何注释来实现这一点?
提前致谢