I'm on a project with Spring and hibernate, in the debugging phase. There are two entities that have their tables created automatically by hbm2ddl. This mostly works fine, but the schema indicates that all columns, except for the primary id, allow null. I would like to tell hbm2ddl to create some of these columns disallowing null values. How could this be achieved?

有帮助吗?

解决方案

You need to specify those constraints in your mapping, whether hbm files or annotations.

For hbm files :

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

For annotations :

@Column(name = "M_LABEL", nullable = false)
private String label;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top