Java Hibernate一对一映射
我不断地发现这个错误:Java Hibernate一对一映射,java,hibernate,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个表 用户->帐户->身份 现在,身份扩展帐户,帐户扩展用户 也许我没有正确地映射。我觉得这有点
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;
}
}我们可以看看您是如何在实体上定义密码字段的吗?我猜你是想用
null
密码保存某物,这违反了@NotNull
或类似required=true
Error saving identity in IdentityDaoImpl. Reason: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.domain.Identity.password
您的密码和类型这两个字段都是可为null的false,异常清楚地表明您试图在密码中插入不可为null的null值。类型也不接受空值。完成。。。是的,我正忙于注册,试图保存用户。请在密码字段中指定nullable=false。。。尝试保留某项内容。在我的register.jsp上使用非Null的值调用setPassword后,我已取出nullable=false和length=255,现在它工作了。但我怀疑输入到密码字段中的文本是否能进入数据库?!