我在hibernate中使用一对一映射我有两个实体RegisterPartner
而另一个Userdetails.userdetails
正在使用user_id
作为主键,并且它在{{中用作外键1}}但是当我保存实体时它正确保存,除了外键变为RegisterPartner
null
@Entity
@Table(name="tbl_login")
public class Userdetails implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="user_id")
private int user_id;
@Column(name="username")
private String username;
@Column(name="password")
private String password;
@OneToOne(mappedBy = "userdetail", cascade = CascadeType.ALL)
private RegisterPartner registerpartner ;
public Userdetails(){
}
}
@Entity
@Table(name="tbl_partner")
public class RegisterPartner implements Serializable , Comparable<RegisterPartner>{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="register_id")
private int register_id;
@Column(name="agency_name")
private String agencyname;
@Column(name="agency_type")
private int agencytype;
@OneToOne
@PrimaryKeyJoinColumn(name = "user_id", referencedColumnName = "user_id")
private Userdetails userdetail;
public RegisterPartner(){}
}
不了解正在发生的事情。
答案 0 :(得分:0)
您不应该使用@PrimaryKeyJoinColumn
,这用于表示主键也是外键。您应该使用@JoinColumn
。