我必须同时更新三个表。当我从邮递员那里命中时,所有表都被成功保存,但是当我尝试更新时,它会引发catch异常,例如同一实体的多种表示形式。
员工详细信息
public class EmployeeDetails implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_id", unique = true, length = 11, nullable = false)
private Integer userId;
//other variable
@OneToOne(mappedBy="user",cascade = CascadeType.ALL)
private EmployeeAdditionalinfo userAdditionalInfo;
@OneToMany(mappedBy="user",cascade = CascadeType.ALL)
private Set<EducationDetails> educationDetail;
//getter and setter
}
EmployeeAdditionalinfo
public class EmployeeAdditionalinfo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_additional_info_id", unique = true, length = 11, nullable = false)
private Integer userAdditionalInfoId;
//other variable
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "user_id")
private EmployeeDetails user;
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "address_id")
private EmployeeAddress address;
//getter or setter }
教育详情
public class EducationDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "s_no", unique = true, length = 10, nullable = true)
private Integer sno;
//variable
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "user_id")
private EmployeeDetails user;
//getter and setter }
错误
org.springframework.dao.InvalidDataAccessApiUsageException:同一实体的多个表示形式[com.icore.Payroll.Attendance.Entity.EmployeeDetails#379]正在合并。分离:[EmployeeDetails [userId = 379,userName =用户名,firstName = Ganesh1,lastName = Babu,middleInitial = Middle,email = Email,password = passwo,......]]
答案 0 :(得分:0)
我认为您只能在关系的一侧配置级联。
当前,由于EmployeeDetails
实体内部的级联配置,您正在触发从EducationDetails
到EmployeeDetails
的集合的所有类型的级联,然后又返回到EducationDetails
。 >
这是有道理的,因为该错误表明我们对同一实体有两种不同的表示(实例),一种在您要刷新的持久性上下文内,另一种在上一次级联期间获取。
您可以尝试删除最后一个配置,并最终手动对其进行管理。