Hibernate naturalID

Hibernate does not seem to generate a nonull constraint for field I marked as naturalID. This is normal?

@MappedSuperclass
public class AbstractDomainObject extends PersistentObject {

 @NaturalId
 private String code;

DB schema: CONSTRAINT SYS_CT_47 UNIQUE (CODE) There is no non-zero constraint.

+3
source share
1 answer

Check out the following excerpt from the Hibernate Handbook:

A natural key is a property or combination of properties that are unique and not equal to zero. He is also unchanged. Match the properties of the natural key as @NaturalId or map them inside the <natural-id> element. Hibernate generates the necessary unique keys and uncertainty constraints, and as a result, your mapping will be more self-documenting.

, (). , @NaturalId (mutable = true)

+3

Source: https://habr.com/ru/post/1739446/


All Articles