Establishing the connection, Defining the hibernate dialect for sql/mx database, Specifying the mapping resources – HP Integrity NonStop J-Series User Manual
Page 186: Opening a session for database operation, Opening a session

Establishing the Connection
To establish the connection, specify the username and password of your NonStop system in the
hibernate.cfg.xml
file under the <session-factory> tag as shown.
<property name="connection.username"><HP NonStop Username></property>
<property name="connection.password"><HP NonStop Password></property>
Defining the Hibernate Dialect for SQL/MX Database
Enter org.hibernate.dialect.SqlmxDialect as the class name of a Hibernate dialect file
in the hibernate.cfg.xml file under the <session-factory> tag.
<property name="dialect">
org.hibernate.dialect.SqlmxDialect
</property>
This dialect file allows Hibernate to generate SQL that is optimized for the SQL/MX database.
Specifying the Mapping Resources
Specify all the mapping files (.hbm) in the <mapping resource> tag as shown:
<!-- Mapping files -->
<mapping resource="<Name of the .hbm file>" />
For example:
If the mapping file used in your application is Employee.hbm.xml, specify it as shown:
<!-- Mapping files -->
<mapping resource="Employee.hbm.xml" />
The basic configuration is ready for you to perform database operation using Hibernate.
Opening a Session for Database Operation
To open a new session for database transaction, complete the following steps:
1.
“Configuring SessionFactory in the hibernate.cfg.xml File” (page 186)
2.
Creating a New Session from the SessionFactory in Java
Configuring SessionFactory in the hibernate.cfg.xml File
Add the following lines in the hibernate.cfg.xml file to configure the Hibernate
SessionFactory
.
<?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>
...
...
...
...
...
</session-factory>
</hibernate-configuration>
NOTE:
The above configuration uses the hibernate-configuration-3.0.dtd file.
Creating a New Session from the SessionFactory in Java
Add the following to create a new session from the SessionFactory:
SessionFactory sessionFactory;
Configuration cfg = new Configuration().configure();
sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.openSession();
186 Configuring Hibernate Applications on NonStop Systems