java Hibernate一对一映射
我不断地发现这个错误:
Error saving identity in IdentityDaoImpl. Reason: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.domain.Identity.password
我已经在一一映射的基础上映射了3个表
用户->;账户->;身份
现在,身份扩展帐户,帐户扩展用户
也许我没有正确地映射。我觉得这有点棘手,因为有3对1的关系,而不是2对1的关系
正确的做法是什么
编辑1:
我已经将所有merge()方法更改为save(),但它没有解决问题
编辑2:
以下是我的实体的干净版本:
@Entity()
@Table(name = "`user`")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name = "type")
@DiscriminatorValue("")
public class User extends ActionSupport implements UserDetails, Serializable {
private static final long serialVersionUID = -7480567862246640031L;
private Integer ID;
private String type;
private String password;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
public Integer getID() {
return ID;
}
public void setID(Integer ID) {
this.ID = ID;
}
@Column(name = "type", nullable = false, unique = false, length = 255)
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
@Column(name = "password", nullable = false, length = 255)
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
# 1 楼答案
您的密码和类型这两个字段都是可为null的false,异常清楚地表明您试图在密码中插入不可为null的null值。类型也不接受空值
# 2 楼答案
我们可以看看您如何定义实体上的密码字段吗?我猜你是想用
null
的密码保存某物,这违反了@NotNull
或类似required=true
的密码