Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 2.14 KB

File metadata and controls

23 lines (17 loc) · 2.14 KB

How To Define A Composite Primary Key Via @IdClass

Description: This application is a proof of concept of how to define a composite key via @IdClass. 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 typical 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

Note: The @IdClass can be useful when we cannot modify the compsite key class. Otherwise, rely on @Embeddable.


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.