Some primary keys consist of more than 1 entity attribute or database column. These are called composite primary keys. They often contain a foreign key reference to a parent object or represent a complex natural key. Another reason to use composite keys is combining a domain-specific value with a simple counter, e.g., an order type and the order number. If this counter gets incremented independently, most developers want to use a database sequence for it.
On the database level, you can model this easily. Your primary key definition references all columns that are part of the primary key. A sequence is an independent object. You request a value during your insert operation and set it as the value of your counter.
The mapping to a JPA entity includes a few challenges that we will solve in this video.
Like my channel? Subscribe!
➜ http://bit.ly/2cUsid8
Read the accompanying post: https://thorben-janssen.com/composite-primary-keys-sequence/
Want to connect with me?
Blog: https://thorben-janssen.com/
Twitter: https://twitter.com/thjanssen123
Facebook: https://www.facebook.com/thorbenjanssenofficial
Linkedin: https://www.linkedin.com/in/thorbenjanssen/
2 Comments