java - 阻止 Hibernate 创建非空约束

标签 java hibernate constraints bean-validation hibernate-validator

有没有办法阻止 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 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.

有关 org.hibernate.validator.group.ddl 属性的更多详细信息,另请参阅 4.1.2. Configuration 部分.

关于java - 阻止 Hibernate 创建非空约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3676778/

相关文章:

java - 如何处理@Transactional注解引发的异常

java - Hibernate 多对多更新

交响乐 4 : Add constraint new UniqueEntity() to x if y is null

swift - 如何向自定义 UITableViewCell 添加约束

java - 如何在java7中为特定用户设置文件访问属性

java - org.apache.axis2.AxisFault : Mapping qname not fond for the package: org. joda.time.chrono

java - 如何解析 Tue Apr 11 00 :00:00 CEST 2017 format in Java? 中的日期

matlab - 使用 fmincon 时动态修复一些变量

java.lang.OutOfMemoryError : Java heap space with 300MB java. exe 上限

java - Java 中等效的并行扩展