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?

Était-ce utile?

La 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;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top