user962206
user962206

Reputation: 16127

Hibernate One To One Bidirectional Not working

I am trying to make my code have a bidrectional relationship(One TO One) But apparently the code is not working.

here's the First Class.

public class User {


    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "USER_PROFILE_FK")
    private UserProfile userProfile;

    //Accessor methods and other stuff
}

and this is the second class

@Entity
@Table(name ="USER_PROFILE")
public class UserProfile{


    @OneToOne(mappedBy="UserProfile")
    private User user;
    //Accessor methods
}

Now when I run my code this exception error occurs

Unknown mappedBy in: org.test.myApp.User, referenced property unknown: org.test.myApp.User.UserProfile

Upvotes: 1

Views: 1898

Answers (1)

JB Nizet
JB Nizet

Reputation: 691785

The field at the other side of the association is named userProfile, not UserProfile, so the mappedBy attribute must be set to userProfile.

Upvotes: 3

Related Questions