Specify default value in Hibernate's XML configuration file

Steve Kuo picture Steve Kuo · May 16, 2012 · Viewed 22.3k times · Source

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?

Answer

Firo picture Firo · May 18, 2012
<property name="age" type="integer">
  <column name="age" not-null="false" default="null" />
</property>