我有兩個表,其中有一個OneToMany,MnatToOne關係。休眠JPA值刪除OneToMany關係
當我將AlarmnotifyEmailEntity的實例添加到alarmnotifyEmailEntityList對象中並更新AlarmnotifyEmailConfEntity的實例時,值會正確保存到數據庫中。
Bu刪除了alarmnotifyEmailEntityList的一個項目時,我無法做同樣的事情。 我肯定值從alarmnotifyEmailEntityList刪除,但它並沒有反映這種變化成數據庫
@Entity(name ="alarmnotify_email_conf")
@Table(name = "alarmnotify_email_conf")
public class AlarmnotifyEmailConfEntity implements Serializable {
@OneToMany(mappedBy = "alarmnotifyEmailConfRef",cascade=CascadeType.ALL)
private List<AlarmnotifyEmailEntity> alarmnotifyEmailEntityList;
}//end of Class
@Entity (name ="alarmnotify_email")
@Table(name = "alarmnotify_email")
public class AlarmnotifyEmailEntity implements Serializable {
@JoinColumn(name = "alarmnotify_email_conf_ref", referencedColumnName = "id")
@ManyToOne
private AlarmnotifyEmailConfEntity alarmnotifyEmailConfRef;
}end of Class
我只是調用下面的語句進行更新。
JPAManager.getJPAManagerInstance()。update(alarmnotifyemailconf);
public Object update(Object o) {
try {
tx.begin();
EntityManager em = getEntityManager();
System.out.println("updating object:" + o);
o = em.merge(o);
em.close();
tx.commit();
System.out.println("closed and commited merge operation");
return o;
}
catch (Exception e) {
e.printStackTrace();
}
return o;
}
你有沒有嘗試添加級聯= CascadeType.ALL的關係@ManyToOne的一面呢? – Asymmetric33
如果@ManyToOne具有CascadeType.All,則觸發刪除AlarmnotifyEmailConfEntity實例。但我不想要這個操作。 –