我有两个表,其中有一个 OneToMany,MnatToOne 关系。
当我将 AlarmnotifyEmailEntity 的实例添加到 alarmnotifyEmailEntityList 对象并更新 AlarmnotifyEmailConfEntity 的实例时,值将正确保存到数据库中。
但是在删除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;
}