我试图使我的代码具有双向关系(一对一),但显然代码无法正常工作。
这是头等舱。
public class User {
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "USER_PROFILE_FK")
private UserProfile userProfile;
//Accessor methods and other stuff
}
这是第二节课
@Entity
@Table(name ="USER_PROFILE")
public class UserProfile{
@OneToOne(mappedBy="UserProfile")
private User user;
//Accessor methods
}
现在当我运行我的代码时会出现这个异常错误
Unknown mappedBy in: org.test.myApp.User, referenced property unknown: org.test.myApp.User.UserProfile
最佳答案
关联另一端的字段名为userProfile
,而不是UserProfile
,因此mappedBy 属性必须设置为userProfile
。
关于java - hibernate 一对一双向不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16073451/