问题
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
?
回答1:
What I usually do is add a unique constraint on the columns, using @Table(uniqueConstraints = @UniqueConstraint(columnNames={column_1, ..., column_n}))
回答2:
No, there is not. You will have to use composite keys, so either EmbeddedId or IdClass depending what you prefer.
来源:https://stackoverflow.com/questions/14254083/jpa-equivalent-to-hibernates-naturalid