我有一个包含对象 messengerData 的 Notification 类:
public class Notification{
@OneToOne(mappedBy = "messengerDataId")
private MessengerData messengerData;
...
}
MessengerData 类包含一个资源映射,这意味着 messengerdata 包含几个,这就是我使用一对多关系的原因:
public class MessengerData{
@OneToOne(mappedBy = "messengerData")
private Notification notification;
@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.REMOVE },
fetch = FetchType.EAGER)
@Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DETACH })
@JoinTable(name = HemisTablesNames.MESSENGER_RESOURCES, joinColumns = @JoinColumn(name = "idResource"),
inverseJoinColumns = @JoinColumn(name = "messengerDataId"))
private Map<String, Resource> resources = new HashMap<String, Resource>();
...
Resource 类包含一个 map<String, NotificationTextData>:
@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.REMOVE },
fetch = FetchType.EAGER)
@Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DETACH })
@JoinTable(name = HemisTablesNames.MESSENGER_NOTIF_TEXT_DATA, joinColumns = @JoinColumn(name = "idNTD"),
inverseJoinColumns = @JoinColumn(name = "idResource"))
private Map<String, NotificationTextData> textDatas;
这是我保存对象的方式:
EntityManager.persist(notification);
EntityManager.commitTransaction();
我的问题是我收到此异常:
无法保存通知:org.hibernate.PersistentObjectException:分离的实体传递给持久化:com.ubiant.hemis.type.Notification
有人可以帮我解决这个问题吗?
长风秋雁
胡说叔叔
相关分类