Modeling sequence-based composite primary keys with Hibernate

preview_player
Показать описание
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!

Want to connect with me?
Рекомендации по теме
Комментарии
Автор

Thanks for this video. With IdClass using a generated value i get below exception. Any idea on this error. Could not set field value [POST_INSERT_INDICATOR] value by reflection : [class setter of

arulpragasam