在春季靴子中使用级联型

时间:2018-04-11 06:48:33

标签: spring-boot

我正在使用spring-boot创建员工数据库管理,我在我的pojo类中使用了Cascade类型。

虽然保存它对我来说很好,但问题是我正在尝试更新员工。

传递给persist的

分离实体:com.cerium.domain.EducationDetails

Employee.java:

package com.cerium.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.Parameter;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import lombok.Getter;
import lombok.Setter;

/**
 * @author Manikanta B Cerium
 *
 */
@Entity
@Table(name = "EMPLOYEE")
public class Employee implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = -1723706191505058961L;

    /**
     * 
     */
    @Getter
    @Setter
    @ManyToOne(cascade = CascadeType.ALL, optional = true, fetch = FetchType.EAGER)
    @JsonBackReference
    private Employee supervisor;

    /**
     * 
     */
    @Id
    @GenericGenerator(name = "emp_id_seq", strategy = "com.cerium.util.EmployeeIdGenerator", parameters = @Parameter(name = "generate", value = "password"))
    @GeneratedValue(generator = "emp_id_seq")
    @Column(name = "employee_id", unique = true, nullable = false, length = 8)
    private String employeeId;


    /**
     * 
     */
    @Getter
    @Setter
    @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
    @LazyCollection(LazyCollectionOption.FALSE)
    private Set<EducationDetails> educationDetails;


    public String getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(String employeeId) {
        this.employeeId = employeeId;
    }

}

注意:我删除了班级中的其他字段。

EducationDetails.java:

package com.cerium.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import lombok.Getter;
import lombok.Setter;

/**
 * @author Manikanta B Cerium
 *
 */
@Entity
@Getter
@Setter
@Table(name = "EDUCATION_DETAILS")
public class EducationDetails implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = -8772845083558480893L;

    /**
     * 
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "EDUCATION_SEQ")
    @SequenceGenerator(name = "EDUCATION_SEQ", sequenceName = "EDUCATION_SEQ")
    private Long educationId;

    /**
     * 
     */
    private String degree;

    /**
     * 
     */
    private String specialization;

    /**
     * 
     */
    private String graduation;

    /**
     * 
     */
    private String nameOfUniversity;

    private String createdBy;

    private Date createdDate;

    private String lastUpdatedBy;

    private Date lastUpdatedDate;

    private Boolean isActive;

    @Override
    public String toString() {
        return String.format(
                "EducationDetails [educationId=%s, degree=%s, specialization=%s, graduation=%s, nameOfUniversity=%s, createdBy=%s, createdDate=%s, lastUpdatedBy=%s, lastUpdatedDate=%s, isActive=%s]",
                educationId, degree, specialization, graduation, nameOfUniversity, createdBy, createdDate,
                lastUpdatedBy, lastUpdatedDate, isActive);
    }

}

我无法理解更新时出现的问题......?

0 个答案:

没有答案