停止Hibernate创建非空约束 [英] Stop Hibernate from creating not-null constraints

查看:155
本文介绍了停止Hibernate创建非空约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 hbm2ddl时,有没有办法阻止Hibernate为使用 @ javax.validation.constraints.NotNull 注释的属性创建非空约束=创建

解决方案

从Hibernate Validator的文档:


6.1。数据库模式级验证



开箱即用,Hibernate Annotations
(从Hibernate 3.5.x开始)会将
您已经为您的实体定义了
的约束条件来映射元数据。
例如,如果您的
实体的属性注释为 @NotNull ,则其
列将被声明为非空

生成的DDL模式Hibernate。



如果由于某种原因,
被禁用,设置
hibernate.validator.apply_to_ddl
false 。另请参阅表格2.2,内置
约束
。您还可以将DDL约束
generation限制为已定义的子集
限制,方法是设置属性
org.hibernate.validator.group.ddl
该属性指定逗号
分隔,完全指定的类名
,约束必须是
的一部分,以便为
DDL模式生成考虑。

有关 org.hibernate.validator.group.ddl 财产,另见 4.1.2。配置


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

解决方案

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.

这篇关于停止Hibernate创建非空约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆