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
  • 60,372
  • 75
  • 191
  • 253

1 Answers1

19
<property name="age" type="integer">
  <column name="age" not-null="false" default="null" />
</property>
Firo
  • 29,778
  • 4
  • 56
  • 93
  • 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