我有一个实体“Employee”和一个@Embeddable类RecycleBin。现在,只要用户删除系统中的任何内容,实体类记录就会重复。我知道这是因为我在RecycleBin类中添加了cascadeType.Merge但是如果我删除了cascadeType.Merge,那么系统会在删除操作时崩溃,从而导致服务器错误“冲洗前保存瞬态”。我已经被困在这两天了,我是春天的新手。如果有人可以帮助我。
这是我的员工类。
@Entity
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Version
private Long version;
private String fullName;
private String fatherName;
private String identityCardNo;
@Temporal(TemporalType.DATE)
private Date dateOfBirth;
private String placeOfBirth;
private String nationality;
private String email;
private String phoneNumber;
@Column(columnDefinition = "TEXT")
private String permanentResAddr;
@Column(columnDefinition = "TEXT")
private String presentResAddr;
@Enumerated(EnumType.STRING)
private MaritalStatus martialStatus;
@Enumerated(EnumType.STRING)
private Gender gender;
private String spouseName;
private String spouseOccupation;
private String spouseOrganization;
private String spouseDesignation;
private String numOfDependents;
private String languagesKnown;
private String salary;
private String bonus;
private String allowance;
private String stipend;
@ElementCollection(fetch = FetchType.EAGER)
@Column(name = "jobrole")
@Enumerated(EnumType.STRING)
private List<JobRole> jobRoles;
@Enumerated(EnumType.STRING)
private JobType jobType;
@ElementCollection(targetClass = Privilege.class, fetch = FetchType.LAZY)
@Column(name = "privilege")
@Enumerated(EnumType.STRING)
private List<Privilege> privileges;
// dep auto del
@OneToMany(mappedBy = "substituteTeacher")
private List<TimetableSubstitute> timetableSubstitutes;
// dep manul del
@OneToMany(mappedBy = "createdBy")
private List<SchemeOfWork> createdSchemeOfWorks;
// dep association del
@OneToMany(mappedBy = "createdBy")
private List<CommentBank> createdComments;
// dep manul del
@OneToMany(mappedBy = "teacher")
private List<BatchSubject> teacherSubjects;
// dep auto del
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "employee_campus", joinColumns = { @JoinColumn(name = "employee", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "branch", referencedColumnName = "id") })
private List<Campus> schoolCampuses;
// dep auto del
@OneToMany(mappedBy = "employee")
private List<CampusEmployeeAttendance> employeeBranchAttendanceList;
// dep auto del
@OneToMany(mappedBy = "employee")
private List<EmployeeAttendance> employeeDayAttendanceList;
// dep association del
@OneToMany(mappedBy = "createdByTeacher")
private List<ProfileForm> teacherCreateProfileForms;
// dep auto del
@ManyToMany(mappedBy = "employees")
private List<Announcement> announcements;
// dep auto del
@OneToMany(mappedBy = "employee")
private List<Notification> notification;
// dep auto del
@OneToOne
private UserLoginAccount employeeLoginAccount;
// dep manul del
@OneToMany(mappedBy = "batchTeacher")
private List<Batch> teacherBatches;
// dep manul del
@OneToOne(mappedBy = "schoolEmployee")
private Parent parent;
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "employee_qualifications", joinColumns = @JoinColumn(name = "emp", referencedColumnName = "id"))
private List<Qualification> qualifications;
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "employee_pre_employment", joinColumns = @JoinColumn(name = "emp", referencedColumnName = "id"))
private List<PreEmployment> preEmployments;
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "employee_memberships", joinColumns = @JoinColumn(name = "emp", referencedColumnName = "id"))
private List<EmpMembership> memberships;
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "employee_certificates", joinColumns = @JoinColumn(name = "emp", referencedColumnName = "id"))
private List<EmpCertificate> certificates;
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "employee_references", joinColumns = @JoinColumn(name = "emp", referencedColumnName = "id"))
private List<EmpReference> references;
// dep auto del
@OneToMany(mappedBy = "employee", fetch = FetchType.LAZY)
private List<FileLibrary> empImages;
@Embedded
private RecycleBin recycleBin;
这是我的RecycleBin类。
@Embeddable
public class RecycleBin {
@Temporal(TemporalType.TIMESTAMP)
private Date deleteDate;
@ManyToOne(cascade= CascadeType.MERGE)
private Employee deletedBy;
@Enumerated(EnumType.STRING)
private RecycleBinStatus recycleBinStatus;