开发者

Hibernate naturalID

开发者 https://www.devze.com 2022-12-25 14:26 出处:网络
Hibernate doesnt seem to g开发者_运维问答enerate a notnull constraint on a field I marked as naturalID. Is this normal?

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消