Skip to content

Files

Latest commit

 

History

History

HibernateSpringBootOneToOneMapsId

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

How To Use @MapsId For Sharing Identifier In @OneToOne Relationships

Description: Instead of regular unidirectional/bidirectional @OneToOne better rely on an unidirectional @OneToOne and @MapsId. This application is a proof of concept.

Key points:

  • use @MapsId on child side
  • use @JoinColumn to customize the name of the primary key column
  • mainly, for @OneToOne associations, @MapsId will share the primary key with the parent table (id property acts as both primary key and foreign key)

Note:

  • @MapsId can be used for @ManyToOne as well

If you need a deep dive into the performance recipes exposed in this repository then I am sure that you will love my book "Spring Boot Persistence Best Practices"If you need a hand of tips and illustrations of 100+ Java persistence performance issues then "Java Persistence Performance Illustrated Guide" is for you.