Ido Barash
Ido Barash

Reputation: 5132

JPA equivalent to Hibernate's @NaturalId

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

Answers (2)

Johanneke
Johanneke

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

Petr Mensik
Petr Mensik

Reputation: 27526

No, there is not. You will have to use composite keys, so either EmbeddedId or IdClass depending what you prefer.

Upvotes: 6

Related Questions