I just started reading about JPA and its implementation in Hibernate. To understand the details better I need some clarification on some of the basics.
When to use
@OneToOne
?
I may use@OneToOne
if the entity manager needs to handle the persistency of the related object. The point is, I can always live without specifying@OneToOne
, but then the responsibility is on me to manage the relationship and make sure that the referred objects are not in transient state.
Is this true?When to use, or not to use
@ManyToOne
?
Say, I'm defining an Employee class and need to define the relationship with the Employer class. In this case, do I need to specify@ManyToOne
as below?@Entity public class Employer { String name; } @Entity class Employee { String name; @ManytoOne //or not?? Employer employer; }