Question

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?

Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top