有没有办法阻止 Hibernate 在使用 hbm2ddl = create
时为使用 @javax.validation.constraints.NotNull
注释的属性创建非空约束?
最佳答案
来自 Hibernate Validator 的文档:
6.1. Database schema-level validation
Out of the box, Hibernate Annotations (as of Hibernate 3.5.x) will translate the constraints you have defined for your entities into mapping metadata. For example, if a property of your entity is annotated
@NotNull
, its columns will be declared asnot null
in the DDL schema generated by Hibernate.If, for some reason, the feature needs to be disabled, set
hibernate.validator.apply_to_ddl
tofalse
. See also Table 2.2, “Built-in constraints”.You can also limit the DDL constraint generation to a subset of the defined constraints by setting the property
org.hibernate.validator.group.ddl
. The property specifies the comma seperated, fully specified classnames of the groups a constraint has to be part of in order to be considered for DDL schema generation.
有关 org.hibernate.validator.group.ddl
属性的更多详细信息,另请参阅 4.1.2. Configuration 部分.
关于java - 阻止 Hibernate 创建非空约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3676778/