环境Hibernate+jpa2 ,新增加int 字段,出异常如下
javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of......
原因:bean中新添加的字段是int类型
private int employeeid;
@Column(name=calendar_employeeid)
public intgetEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
当数据库中该字段为null时,就会报错
解决方法1:该bean 中相应字段int 改为Integer
@Column(name=calendar_employeeid)
public Integer getEmployeeId() {
return employeeId;
}
public void setEmployeeId(Integer employeeId) {
this.employeeId = employeeId;
}
解决方法2:数据库中相应字段默认不为null