Stop Hibernate from creating not-null constraints

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 12:18:34

问题


Is there a way to stop Hibernate from creating not-null constraints for properties annotated with @javax.validation.constraints.NotNull when using hbm2ddl = create?


回答1:


From the documentation of 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 as not null in the DDL schema generated by Hibernate.

If, for some reason, the feature needs to be disabled, set hibernate.validator.apply_to_ddl to false. 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.

For more details about the org.hibernate.validator.group.ddl property, see also the section 4.1.2. Configuration.



来源:https://stackoverflow.com/questions/3676778/stop-hibernate-from-creating-not-null-constraints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!