当我提交表单时,我得到了这个错误-“org.hibernate.propertyvalueexception:notnull属性引用了一个null或暂时值”,请帮助。我在stackoverflow中提到了类似的问题,但我无法解决
//下面的用户类
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable=false, unique = true, length = 45)
private String email;
@Column(nullable=false, length = 64)
private String password;
@Column(nullable=false, length = 20)
private String firstName;
@Column(nullable=false, length = 20)
private String lastName;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
1条答案
按热度按时间rta7y2nd1#
由于您的用户类没有关联的其他实体,因此在提交表单时,似乎至少有一个email、password、first或last name属性为null。在保存用户类之前,如果这些属性中的任何一个为null,那么您应该在那里得到答案。