You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it currently possible to have a multi-column primary key?
For example, imagine a table of passports, and each person can actually get several passports over the course of their life. Thus, the unique primary key for a passport might be (PassportId, IssueDate).
With Hibernate, this is often accomplished using an @Embeddable class, but annotating it with @EmbeddedId rather than just @Id.
A workaround to this problem (if one can add an additional column), is to make a string column that combines multiple other columns, and compute this column as a D @property, e.g.
Just adding a note here that support for @JoinColumns should be added as well, so that automatic object references can be decoded. As it is, @EmbeddedId adds quite a bit of value when dealing with existing databases that use multi-column primary keys, but its value could be further enhanced.
Consider the following relationship that is not currently supported but could be. In this case, we have contracts with vendors, and each contract can have many invoices against it. Invoices have IDs, but each vendor creates their own IDs unaware of each other, and they might re-use the same invoice_id for different contracts, thus, only the (vendor_id, contract_id, invoice_id) is unique.
Is it currently possible to have a multi-column primary key?
For example, imagine a table of passports, and each person can actually get several passports over the course of their life. Thus, the unique primary key for a passport might be
(PassportId, IssueDate)
.With Hibernate, this is often accomplished using an
@Embeddable
class, but annotating it with@EmbeddedId
rather than just@Id
.https://www.baeldung.com/spring-jpa-embedded-method-parameters
A workaround to this problem (if one can add an additional column), is to make a string column that combines multiple other columns, and compute this column as a D
@property
, e.g.The text was updated successfully, but these errors were encountered: