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?
Inserting a default value can be done in various ways such as Default entity property value using constructor or setter. Other ways like using JPA with columnDefinition have the drawback that they insert a null by default and the default value of the DBMS does not precede.
Hibernate also requires a set of configuration settings related to database and other related parameters. All such information is usually supplied as a standard Java properties file called hibernate. properties, or as an XML file named hibernate. cfg.
Basically you are setting all the required properties via your properties object so there is no real need to tell Hibernate to look for a hibernate. cfg. xml file which is exactly what the configure() method does.
<property name="age" type="integer">
<column name="age" not-null="false" default="null" />
</property>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With