0
我嘗試使用Hibernate創建一對一的映射。而當我實現DAO方法,我收到以下錯誤:未知mappedBy in ...引用屬性未知錯誤
org.hibernate.AnnotationException: Unknown mappedBy in: com.User.userData, referenced property unknown: com.UserData.user
java.lang.NullPointerException
爲什麼我得到這個錯誤?
我的代碼是這樣的:
對於用戶實體代碼:
@Entity
@Table(name = "user")
public class User implements Serializable {
@Id
@GeneratedValue
@Column(name = "userid")
int userID;
@OneToOne(fetch = FetchType.LAZY, mappedBy = "user", cascade = CascadeType.ALL)
UserData userData;
...
}
對於實體的UserData代碼:
@Entity
@Table(name = "UserData")
public class UserData {
@Id
@GeneratedValue(generator = "generator")
@GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "user"))
int userID;
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
User user;
請考慮刪除@PrimaryKeyJoinColumn – Koitoer