- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在尝试使用 Hibernate 从数据库中删除 Patient 对象时遇到标题错误。
这是我的 Patient Java 类:
package com.vivalio.springmvc.model
@Entity
@Table(name = "PATIENT")
@PrimaryKeyJoinColumn(name = "id")
public class Patient extends User implements Serializable {
@ManyToOne
@JoinColumn(name = "docteur_id", referencedColumnName = "id")
private Docteur docteur;
@OneToMany(fetch = FetchType.EAGER, orphanRemoval = true, mappedBy = "patient", cascade = CascadeType.ALL)
@OrderBy("dateCreation desc")
private Set<Consultation> consultations = new HashSet<Consultation>();
public Set<Consultation> getConsultations() {
return consultations;
}
public void setConsultations(Set<Consultation> consultations) {
this.consultations = consultations;
}
public Docteur getDocteur() {
return docteur;
}
public void setDocteur(Docteur docteur) {
this.docteur = docteur;
}
}
这是我的咨询类(class):
@Entity
@Table(name = "CONSULTATION")
public class Consultation implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "CONSID")
private Integer id;
// poid
@NotEmpty
@Column(name = "PARAM1", nullable = false)
private String param1;
// appetit
@NotEmpty
@Column(name = "PARAM2", nullable = false)
private String param2;
// faiblesse
@NotEmpty
@Column(name = "PARAM3", nullable = false)
private String param3;
// douleur
@NotEmpty
@Column(name = "PARAM4", nullable = false)
private String param4;
// boule
@NotEmpty
@Column(name = "PARAM5", nullable = false)
private String param5;
// fievre
@NotEmpty
@Column(name = "PARAM6", nullable = false)
private String param6;
// Commentaire
@NotEmpty
@Column(name = "COMMENTAIRE", nullable = false)
private String commentaire;
@Column(name = "DTCREATION", nullable = true)
private String dateCreation;
@Column(name = "JJCREATION", nullable = true)
private String jjCreation;
@Column(name = "MMCREATION", nullable = true)
private String mmCreation;
@Column(name = "YYCREATION", nullable = true)
private String aaCreation;
@ManyToOne
@JoinColumn(name = "patient_id")
private Patient patient;
public String getParam1() {
return param1;
}
public void setParam1(String param1) {
this.param1 = param1;
}
public String getParam2() {
return param2;
}
public void setParam2(String param2) {
this.param2 = param2;
}
public String getParam3() {
return param3;
}
public void setParam3(String param3) {
this.param3 = param3;
}
public String getParam4() {
return param4;
}
public void setParam4(String param4) {
this.param4 = param4;
}
public String getParam5() {
return param5;
}
public void setParam5(String param5) {
this.param5 = param5;
}
public String getParam6() {
return param6;
}
public void setParam6(String param6) {
this.param6 = param6;
}
public String getDateCreation() {
return dateCreation;
}
public Patient getPatient() {
return patient;
}
public void setPatient(Patient patient) {
this.patient = patient;
}
public void setDateCreation(String dateCreation) {
this.dateCreation = dateCreation;
}
public String getJjCreation() {
return jjCreation;
}
public void setJjCreation(String jjCreation) {
this.jjCreation = jjCreation;
}
public String getMmCreation() {
return mmCreation;
}
public void setMmCreation(String mmCreation) {
this.mmCreation = mmCreation;
}
public String getAaCreation() {
return aaCreation;
}
public void setAaCreation(String aaCreation) {
this.aaCreation = aaCreation;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCommentaire() {
return commentaire;
}
public void setCommentaire(String commentaire) {
this.commentaire = commentaire;
}
}
执行下面的代码后,我遇到了这个错误:
@Override
public void deleteBySSO(String sso) {
Criteria crit = createEntityCriteria();
crit.add(Restrictions.eq("ssoId", sso));
Patient user = (Patient) crit.uniqueResult();
delete(user);
}
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/vivalio] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.vivalio.springmvc.model.Patient#34]; nested exception is org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.vivalio.springmvc.model.Patient#34]] with root cause org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.vivalio.springmvc.model.Patient#34] at org.hibernate.internal.SessionImpl.forceFlush(SessionImpl.java:1272) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:187) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:114) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90) at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:684)
最佳答案
您需要从集合中删除对象或将 FetchType 设置为延迟加载
deleted object would be re-saved by cascade (remove deleted object from associations)
关于java - org.hibernate.ObjectDeletedException : deleted object would be re-saved by cascade : Error while trying to delete a Patient object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45910335/
我只是不明白为什么 Hibernate 会抛出标题中提到的异常。我可能不了解 Hibernate 背后的状态管理思想。 我有以下情况: 组织与员工的一对多关系 组织.hmb.xml
我有一个包含多个发票项目的发票对象。根据用户的选择,我需要将一些项目从一张发票移动到另一张发票。我正在使用 MySql 和 Hibernate。 发票项目定义为延迟加载,如下所示: 在 Java 中我
我正在尝试在 hibernate 中映射 3 个实体之间的级联关系。这些实体是 1.Item --has a Maker and a Distributor. 2.Maker --has a set
我有一个包含书籍对象列表的用户类。一旦用户的记录被创建,他所借的所有书籍都将被添加到他的对象中的书籍列表中。一旦用户删除了他的个人资料,就需要保留借书的记录和历史。 许多注册用户可能会经常借书并删除他
这是我的删除方法: public void removeIletisimAdresi(Integer index){ getUser().getIletisimBilgil
我收到上述错误“org.hibernate.ObjectDeletedException:已删除的对象将通过级联重新保存(从关联中删除已删除的对象):”。有人可以帮助我可能是什么问题,应该解决什么问题
当我尝试从属于 Ticket 类的集合中删除 TicketLine 对象并且 TicketLine 与 Reservation 类具有 OneToOne 关联时,我遇到了“已删除的对象将通过级联重新保
我在尝试使用 Hibernate 从数据库中删除 Patient 对象时遇到标题错误。 这是我的 Patient Java 类: package com.vivalio.springmvc.model
我是一名优秀的程序员,十分优秀!