在我的 Spring Boot 應用程序中,我有User這樣的類:public class User {@Id @GeneratedValue Long userID;@OneToOne(fetch = FetchType.LAZY,targetEntity = LoginCredential.class)@JoinColumn(name = "userID",referencedColumnName = "userID")private LoginCredential loginCredential;}另一個類LoginCreadential是這樣的:public class LoginCredential {@Id @GeneratedValue Long userID;@OneToOne(mappedBy = "user", fetch = FetchType.LAZY)User user;}在我嘗試添加這些關系之前,我的應用程序運行良好?,F在它不運行。它給了我錯誤(很多),但重要的部分在這里:org.hibernate.AnnotationException:未知 mappedBy in:com.mua.cse616.Model.LoginCredential.user,引用屬性未知:com.mua.cse616.Model.User.user這里的錯誤是什么?如何解決?
1 回答

守候你守候我
TA貢獻1802條經驗 獲得超10個贊
這是因為mappedBy
必須有一個值,該值是包含這些實體之間映射的字段的名稱。
在您的示例中,這應該是mappedBy = "loginCredential"
,因為@OneToOne
包含mappedBy
注釋User
。User
另一方面使用@JoinColumn(name = "userID",referencedColumnName = "userID")
overloginCredential
字段定義那些實體之間的映射,因此 的值mappedBy
。
添加回答
舉報
0/150
提交
取消