We can think of a
@OneToOne relationship pair as
the same as a
@ManyToOne relationship pair but with the
addition that the "many" side has a cardinality of "at most 1".
From a Relational database perspective the @OneToOne relationship pair is
like the @OneToMany/@ManyToOne pair but with the
addition of a unique
constraint which effectively limits the cardinality of the "many" side to be "at most 1".
From the perspective of Ebean internals. The @OneToOne(mappedBy=) acts much like the @OneToMany(mappedBy=) [the "many" side] and the other @OneToOne acts like the @ManyToOne [the "one" side].
@OneToOne "many" side
The "many" side @OneToOne has the
mappedBy attribute (like @OneToMany).
@Entity public class Wheel ... // has "mappedBy" (like @OneToMany) // ... so we can think of this as the "many" side // ... with cardinality limited to "at most 1" @OneToOne(mappedBy = "wheel") Tire tire; ...
@OneToOne "one" side
The "one" side @OneToOne has no
This side acts almost exactly like @ManyToOne.
This side maps to the foreign key column. If the foreign key column does not match the
naming convention we can specify a
@Entity public class Tire ... // no mappedBy (like @OneToMany) // ... so the "one" side of the relationship // ... means it maps to the foreign key // ... use @JoinColumn if needed @OneToOne @JoinColumn(name = "wheel") Wheel wheel;