Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 如何将hbm2ddl设置为在某些变量/列中不允许null?_Spring_Hibernate_Hbm2ddl - Fatal编程技术网

Spring 如何将hbm2ddl设置为在某些变量/列中不允许null?

Spring 如何将hbm2ddl设置为在某些变量/列中不允许null?,spring,hibernate,hbm2ddl,Spring,Hibernate,Hbm2ddl,我正在调试Spring和hibernate的项目。有两个实体的表由hbm2ddl自动创建。这基本上可以正常工作,但模式指示除主id之外的所有列都允许null。我想告诉hbm2ddl创建一些不允许空值的列。如何实现这一点?您需要在映射中指定这些约束,无论是hbm文件还是注释 对于hbm文件: <property type="string" name="label" column="M_LABEL" not-null="true"/> 对我是朝那个方向想的。不过,我正在使用注释,在找到

我正在调试Spring和hibernate的项目。有两个实体的表由hbm2ddl自动创建。这基本上可以正常工作,但模式指示除主id之外的所有列都允许null。我想告诉hbm2ddl创建一些不允许空值的列。如何实现这一点?

您需要在映射中指定这些约束,无论是hbm文件还是注释

对于hbm文件:

<property type="string" name="label" column="M_LABEL" not-null="true"/>

对我是朝那个方向想的。不过,我正在使用注释,在找到正确的注释时遇到了一些困难。你的暗示使我走上了正确的道路。我需要添加的是@Column注释中的nullable=false。我错误地寻找NotNull(用于Spring验证)或类似的东西。谢谢
@Column(name = "M_LABEL", nullable = false)
private String label;