JPA equivalent to Hibernate's @NaturalId

坚强是说给别人听的谎言 提交于 2019-11-30 14:02:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!