I\'m trying to get Hibernate @OneToOne annotations working and not having much success here...
Let\'s say I\'ve got a table called status
that looks lik
use this way. Add below field in Customer entity.
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "customer")
private Status status;
and don't add getter and setter for status field in Customer entity. And add below code to Status Entity.
@OneToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "customer_id", nullable = false)
private Customer customer;
Here add the getter and setter for customer field in Status Entity class. You can see one working example here.
Your Status entity must not have properties userId
and contentId
of type Integer, mapped with @Column
. It must have properties user
and content
of type User and Content, mapped with @OneToOne
:
public class User {
@OneToOne(mappedBy = "user")
private Status status;
// ...
}
public class Status {
@OneToOne
@JoinColumn(name = "frn_user_id")
private User user;
// ...
}
A user has one status. A status has one user.