How does a @OneToOne relationship work in Spring Data JPA?

Your thoughts?


A @OneToOne relationship is self explanatory (at least on the surface level). One customer has one address. One author has one book..

But using the JPA @OneToOne annotation specifically means that you are utilizing an ORM provider (like Hibernate) under the hood to implement the code/logic for creating tables, relationships (foreign keys, primary keys) so that you don't have to worry about it.

JPA defines runtime annotation interfaces like @OneToOne. It is up to the ORM providers (like Hibernate) to implement this. At runtime, Hibernate will generate the code you need to generate the tables you need.


A @OneToOne annotation provides runtime code for generating the schema, tables you need to achieve a one to one relational database relationship.


One Book. One Author

One House. One Mortgage.

One Building. One Foundation.

One World. One Universe.

Catch the drift?


A @OneToOne isn't really Spring Data JPA..more JPA specification..just saying..


it generates your one to one relationships like magic...