9

I'm configuring Hibernate via the mapping configuration file.

<class name="Person" table="person">
    <id name="id" column="id" type="long"/>
    <property name="name" column="name" type="string"/>
    <property name="age" column="age" type="integer"/>
</class>

How do I set age to be nullable and default to null?

Steve Kuo
  • 61,876
  • 75
  • 195
  • 257

1 Answers1

20
<property name="age" type="integer">
  <column name="age" not-null="false" default="null" />
</property>
Firo
  • 30,626
  • 4
  • 55
  • 94
  • isn't `default="null"` the same as just specifying no default at all? – Tim Büthe Jun 08 '16 at 11:22
  • Yes it is. I wrote it purely to demonstrate how to specify the default value. Normally you would make the property a nullable integer so NHibernate would figure out the nullable by itself. – Firo Jun 09 '16 at 07:01