Setting hibernate configurations, Hibernate.cfg.xml – HP Integrity NonStop J-Series User Manual

Page 137

Advertising
background image

length="15"
column="lname"/>

<property name="age" column="age" />

</class>

</hibernate-mapping>

NOTE:

The generator class for tag <id> is increment. This is to use the auto-increment

feature of Hibernate.

Setting Hibernate Configurations

To set up Hibernate configurations, create and modify the following files:

hibernate.cfg.xml

hibernate.properties

hibernate.cfg.xml

This file is used to set up the environment.
1.

Create the hibernate.cfg.xml file in the EmployeeInfo/src directory, as explained
in

“Creating the Hibernate Mapping File” (page 134)

.

2.

Modify the file as follows:

Add a reference for the Hibernate mapping file under the <session-factory> tag.

<mapping resource="Employee.hbm.xml" />

Add a reference for the Hibernate dialect file by including the following property tag
under the <session-factory> tag.

<property name="dialect">
org.hibernate.dialect.SqlmxDialect
</property>

Enable auto-creation of database tables using the Hibernate mapping file by including
the following property tag under the <session-factory> tag.

<property name="hibernate.hbm2ddl.auto">create</property>

The hibernate.cfg.xml file now appears as:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>

<property name="hibernate.hbm2ddl.auto">create</property>
<property name="show_sql">true</property>

<!-- SQL Dialect to use. Dialects are database specific -->
<property name="dialect">
org.hibernate.dialect.SqlmxDialect
</property>
<!-- Mapping files -->
<mapping resource="Employee.hbm.xml" />
</session-factory>
</hibernate-configuration>

Getting Started with Hibernate

137

Advertising
This manual is related to the following products: