java - Unknown mappedBy in ... referenced property unknown error -
I tried to create one-to-one mapping using hibernate and when I am implementing the DAO method, I am getting the following error:
org.hibernate.AnnotationException: unknown is mapped: com.User.userData, referenced property unknown: com.UserData user java.lang.NullPointerException < / Code>
Why am I getting this error?
My codes are as follows:
For user unit code:
@Entity @Table (name = "user") Public category User Serializable applies {@Id @GeneratedValue @Column (name = "userid") int userID; @OneToOne (fetch = FetchType.LAZY, mapped = "user", cascade = cascade type.Al) user data utility; ...}
For the UserData unit code:
@inti @Table (name = "UserData") public class UserData {@Id @GeneratedValue (Generator = "generator") @GenericGenerator (name = "generator", strategy = "foreign", parameter = @Parameter (name = "property", value = "user")) int userID; @OneToOne (fetch = FetchType.LAZY) @PrimaryKeyJoinColumn User User; mappedBy
change mappedBy = user
= UserID . That should solve your problem.
Although its strange you are trying to do a bidirectional one, it seems only for an unidirectional requirement that a bidirectional relationship implies that you have your UserDetails object inside and vice versa. The user can use the object, but I think you only need to use your UserDetails object from your user object, not the other way around from around.
In addition, you do not need to specify FetchType.LAZY, it is the default option anyway.
If you want to replace it with a unidirectional one, just change your user class to:
@OneToOne @PrimaryKeyJoinColumn Personal UserData UserData
And leave all the references of the user inside your UserData class.
If this problem is not correct, tell me
Comments
Post a Comment