Skip to content

Files

Latest commit

655ec44 · Nov 27, 2019

History

History

HibernateSpringBootCompositeKeyEmbeddable

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Oct 10, 2019
Nov 27, 2019
Oct 10, 2019

How To Define A Composite Primary Key Via @Embeddable

Description: This application is a proof of concept of how to define a composite key via @Embeddable and @EmbeddedId. This application uses two entities, Author and Book involved in a lazy bidirectional @OneToMany association. The identifier of Author is composed by name and age via AuthorId class. The identifier of Book is just a regular auto-generated numeric value.

Key points:

  • the composite key class (e.g., AuthorId) is public
  • the composite key class must implement Serializable
  • the composite key must define equals() and hashCode()
  • the composite key must define a no-arguments constructor

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.