我正在创建一个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;
}
}
我已经包含了我正在使用的实体的代码 - 组织,员工和时间日志。
答案 0 :(得分:0)
我终于解决了这个问题。 这是由于重新命名我的文件夹,其中重新创建了实体代码。我将文件夹名称更改为以前的名称并解决了问题