Hibernate naturalID
Hibernate doesnt seem to g开发者_运维问答enerate a notnull constraint on a field I marked as naturalID. Is this normal?
@MappedSuperclass
public class AbstractDomainObject extends PersistentObject {
@NaturalId
private String code;
DB Schema: CONSTRAINT SYS_CT_47 UNIQUE(CODE) There is no not null constraint here.
Checkout the following excerpt from Hibernate's reference manual:
A natural key is a property or combination of properties that is unique and non-null. It is also immutable. Map the properties of the natural key as @NaturalId or map them inside the <natural-id> element. Hibernate will generate the necessary unique key and nullability constraints and, as a result, your mapping will be more self-documenting.
Note also that by default, natural identifier properties are assumed to be immutable (constant) You can change the default by specifying @NaturalId (mutable = true)
精彩评论