In Hibernate I can create a unique key using @NaturalId
on several properties of the entity.
Is there a JPA equivalent annotation, something that is a part of javax.persistence
?
In Hibernate I can create a unique key using @NaturalId
on several properties of the entity.
Is there a JPA equivalent annotation, something that is a part of javax.persistence
?
What I usually do is add a unique constraint on the columns, using @Table(uniqueConstraints = @UniqueConstraint(columnNames={column_1, ..., column_n}))
@NaturalId
as a "secondary" id, together with @Id Integer id
. @NaturalId
really like an unique constraints together with NOT NULL and I doubt, it can be used as primary id. –
Intumescence No, there is not. You will have to use composite keys, so either EmbeddedId or IdClass depending what you prefer.
© 2022 - 2024 — McMap. All rights reserved.