java - Hibernate Java - 无法反序列化/无效流头错误

标签 java hibernate spring-boot

我正在创建一个 Java Spring Boot 项目。我遇到了其中一个表的外键问题,其中空值被插入到外键字段中。我无法解决该问题,因此我使用 Eclipse IDE 的 Hibernate 配置重新创建了实体代码。现在我可以启动应用程序,但在 Postman 中收到以下错误。

{
    "timestamp": 1519124137813,
    "status": 500,
    "error": "Internal Server Error",
    "exception": "org.springframework.orm.jpa.JpaSystemException",
    "message": "could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize",
    "path": "/employee/"
}

{
    "timestamp": 1519125015097,
    "status": 500,
    "error": "Internal Server Error",
    "exception": "org.springframework.orm.jpa.JpaSystemException",
    "message": "could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize",
    "path": "/employee/101/timelog/tabdata"
}

我的疑问:我使用的是localdateconverter。我怀疑是否是日期转换问题

//员工

// default package
// Generated Feb 18, 2018 3:41:47 PM by Hibernate Tools 5.2.3.Final

/**
 * Employee generated by hbm2java
 */
@Entity
@Table(name = "employee", catalog = "timesheet")
public class Employee implements java.io.Serializable {

    private static final long serialVersionUID = -8265127921786950582L;
    private Integer empId;
    @JsonIgnore
    private Organisation organisation;
    private String designation;
    private String email;
    private String empName;
    private String gender;
    private LocalDate joinDate;
    private Set<Timelog> timelogs = new HashSet<Timelog>(0);

    public Employee() {
    }

    public Employee(Organisation organisation) {
        this.organisation = organisation;
    }

    public Employee(Organisation organisation, String designation, String email, String empName, String gender,
            LocalDate joinDate, Set<Timelog> timelogs) {
        this.organisation = organisation;
        this.designation = designation;
        this.email = email;
        this.empName = empName;
        this.gender = gender;
        this.joinDate = joinDate;
        this.timelogs = timelogs;
    }


    public Employee(String empName, LocalDate joinDate, String gender, String designation, String email) {
        // TODO Auto-generated constructor stub
        this.empName = empName;
        this.joinDate = joinDate;
        this.gender = gender;

        this.designation = designation;
        this.email = email;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)

    @Column(name = "emp_id", unique = true, nullable = false)
    public Integer getEmpId() {
        return this.empId;
    }

    public void setEmpId(Integer empId) {
        this.empId = empId;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "org_id", nullable = false)
    public Organisation getOrganisation() {
        return this.organisation;
    }

    public void setOrganisation(Organisation organisation) {
        this.organisation = organisation;
    }

    @Column(name = "designation", length = 45)
    public String getDesignation() {
        return this.designation;
    }

    public void setDesignation(String designation) {
        this.designation = designation;
    }

    @Column(name = "email", length = 45)
    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "emp_name", length = 45)
    public String getEmpName() {
        return this.empName;
    }

    public void setEmpName(String empName) {
        this.empName = empName;
    }

    @Column(name = "gender", length = 10)
    public String getGender() {
        return this.gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    //@Temporal(TemporalType.DATE)
    @Column(name = "join_date", length = 10)
    public LocalDate getJoinDate() {
        return this.joinDate;
    }

    public void setJoinDate(LocalDate joinDate) {
        this.joinDate = joinDate;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "employee")
    public Set<Timelog> getTimelogs() {
        return this.timelogs;
    }

    public void setTimelogs(Set<Timelog> timelogs) {
        this.timelogs = timelogs;
    }

    public void addLog(Timelog log) {
        Set<Timelog> set = this.getTimelogs();
        set.add(log);
        this.setTimelogs(set);
    }

}

//组织

/**
 * Organisation generated by hbm2java
 */
@Entity
@Table(name = "organisation", catalog = "timesheet")
public class Organisation implements java.io.Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 5790958954280933376L;
    private Integer orgId;
    private String address;
    private Integer contactNo;
    private String email;
    private String name;
    private Set<Employee> employees = new HashSet<Employee>(0);

    public Organisation() {
    }

    public Organisation(String address, Integer contactNo, String email, String name, Set<Employee> employees) {
        this.address = address;
        this.contactNo = contactNo;
        this.email = email;
        this.name = name;
        this.employees = employees;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)

    @Column(name = "org_id", unique = true, nullable = false)
    public Integer getOrgId() {
        return this.orgId;
    }

    public void setOrgId(Integer orgId) {
        this.orgId = orgId;
    }

    @Column(name = "address", length = 45)
    public String getAddress() {
        return this.address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Column(name = "contact_no")
    public Integer getContactNo() {
        return this.contactNo;
    }

    public void setContactNo(Integer contactNo) {
        this.contactNo = contactNo;
    }

    @Column(name = "email", length = 45)
    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "name", length = 45)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "organisation")
    public Set<Employee> getEmployees() {
        return this.employees;
    }

    public void setEmployees(Set<Employee> employees) {
        this.employees = employees;
    }

}

//时间日志表

@Entity
@Table(name = "timelog", catalog = "timesheet")
public class Timelog implements java.io.Serializable {
private static final long serialVersionUID = 1871977717947082854L;
private Integer id;
private Employee employee;
private LocalDate logDate;
private String project;
private Float timetaken;

public Timelog() {
}

public Timelog(Employee employee) {
    this.employee = employee;
}

public Timelog(Employee employee, LocalDate logDate, String project, Float timetaken) {
    this.employee = employee;
    this.logDate = logDate;
    this.project = project;
    this.timetaken = timetaken;
}

public Timelog(LocalDate logDate, String project, float timetaken) {
    this.logDate = logDate;
    this.project = project;
    this.timetaken = timetaken;
}

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
    return this.id;
}

public void setId(Integer id) {
    this.id = id;
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "emp_id", nullable = false)
public Employee getEmployee() {
    return this.employee;
}

public void setEmployee(Employee employee) {
    this.employee = employee;
}

//@Temporal(TemporalType.DATE)
@Column(name = "logDate", length = 10)
public LocalDate getLogdate() {
    return this.logDate;
}

public void setLogdate(LocalDate logDate) {
    this.logDate = logDate;
}

@Column(name = "project", length = 45)
public String getProject() {
    return this.project;
}

public void setProject(String project) {
    this.project = project;
}

@Column(name = "timetaken", precision = 12, scale = 0)
public Float getTimetaken() {
    return this.timetaken;
}

public void setTimetaken(Float timetaken) {
    this.timetaken = timetaken;
}

}

我已经包含了我正在使用的实体的代码 - 组织、员工和时间日志。

最佳答案

我终于解决了这个问题。 这是由于重命名了在其中重新创建实体代码的文件夹而引起的。我将文件夹名称更改为之前的名称,问题得到解决

关于java - Hibernate Java - 无法反序列化/无效流头错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48884018/

相关文章:

spring-boot - 定义微服务边界

java - Spring Boot 集成流程应用程序在启动时关闭

java - "style="?textTitle"是什么意思,它是如何工作的?

java - 在我的 Java2D 程序中定期调用 repaint() 的最佳方法是什么?

java - 如何通过 Swing 中的中间面板使 View 居中

java - 为什么不推荐使用 org.hibernate.cache.Cache?

hibernate - 保存对象后获取id

java - 带复合键的 Hibernate 单向 OneToMany

java - 如何在 NetBeans 中禁用 javadoc 拼写检查器

spring-boot - Spring 数据休息 : "Unable to configure LocalContainerEntityManagerFactoryBean from @EntityScan"