one-to-one unidirectional association

/, JPA/one-to-one unidirectional association

In a relational database in a one-to-one relationship, a row in table X can have no more than one matching row in table Y, and vice versa. X one-to-one relationship is created if both of the related columns are primary keys or have unique constraints.

In Object oriented programming, one instance of entity exactly refers to one instance of another entity in the  relation called one-to-one relation.

Tables structure in Database :

User Entity Mapping :

Credentials Entity Mapping :

Cascade :

  • Whenever rows in the parent table manipulated (inserted, updated, deleted) the respective rows of the child table with a matching key column will be manipulated as well. This is called Cascade in Database.
  • JPA translates entity state transitions to database DML statements.

@JoinColumn :

  • @JoinColumn Specifies a column for joining an entity association or element collection. The annotation MARKDOWN_HASHf6fe5d6d260954e3d74370aaeb356271MARKDOWN_HASH indicates that this entity is the owner of the relationship. That is the corresponding table has a column with a foreign key to the referenced table.
To Understand Cascade and @JoinColumn mapping in entity associations see :
Key points to understand associations

Testing one-to-one  mapping :

Console Output :

Download Application – (14 KB)
2017-08-31T12:41:45+00:00Categories: Hibernate, JPA|Tags: , , , |0 Comments

Leave A Comment