gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 10:41:57 24 4
gpt4 key购买 nike

我正在创建一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com