One to One Mapping in JPA

In this example I am going to show you how we can implement One to One(@OneToOne) relationship using JPA persistence API in Java.

The Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects / classes and a relational database.

The JPA is used to reduce the burden of writing codes for relational object management, a programmer or developer follows the ‘JPA Provider’ framework, which allows easy interaction with database instance. The JPA being a Java framework a programmer also needs not to worry about the SQL part of the code, he/she may need to hardly concentrate on SQL coding.

You may be interested in Many to One Mapping in JPA , Many to Many Mapping in JPA and One to Many Mapping in JPA

In One-To-One relationship, one item can be linked to only one other item. It means each row of one entity is referred to one and only one row of another entity.

In this One to One mapping example, we have Teacher and Period relationship. A class period can be taken by only one teacher.

Continue reading “One to One Mapping in JPA”