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?
Asked
Active
Viewed 185 times
1 Answers
1
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;

overmeulen
- 1,158
- 6
- 15
-
Yes. I was thinking in that direction. I'm working with annotations though, and had some trouble finding the right one. Your hint put me on the right track. What I needed to add was nullable=false inside the @Column annotation. I was incorrectly looking for an NotNull (which is used in Spring Validation) or something similar. Thanks! – Marceau Feb 21 '13 at 09:17