Reputation: 5132
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
?
Upvotes: 13
Views: 13540
Reputation: 5773
What I usually do is add a unique constraint on the columns, using @Table(uniqueConstraints = @UniqueConstraint(columnNames={column_1, ..., column_n}))
Upvotes: 9
Reputation: 27526
No, there is not. You will have to use composite keys, so either EmbeddedId or IdClass depending what you prefer.
Upvotes: 6