naturalid

Hibernate 5.2 get natural id properties from metamodel

醉酒当歌 提交于 2019-12-11 01:49:00
问题 Since SessionFactory#getClassMetadata(java.lang.Class) was deprecated, I am not able to use ClassMetadata. I would like to access to the following methods: org.hibernate.metadata.ClassMetadata#getNaturalIdentifierProperties org.hibernate.metadata.ClassMetadata#hasNaturalIdentifier According to the documentation, I should replace getClassMetada with EntityManagerFactory.getMetamodel(). However, the metamodel does not contain methods to get natural-id. I am using xml mapping for natural-id and

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