Closing the session, Hibernate.properties, Configuring sessionfactory in the – HP Integrity NonStop H-Series User Manual
Page 320: Hibernate.cfg.xml, File, Creating a new session from the, Sessionfactory, In your java program
Configuring SessionFactory in the
hibernate.cfg.xml
File
Add the following lines in the
hibernate.cfg.xml
file to configure the Hibernate
SessionFactory
.
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
...
...
...
...
...
NOTE:
The above configuration uses the
hibernate-configuration-3.0.dtd
file.
Creating a New Session from the
SessionFactory
in your Java Program
To create a new session from
SessionFactory
, add the following lines of code in your Java
program:
SessionFactory sessionFactory;
Configuration cfg = new Configuration().configure();
sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.openSession();
NOTE:
To view the complete configuration snippet of
hibernate.cfg.xml
, see the
Closing the Session
Once the database operation is complete, close the session to deallocate the memory.
Add the following line of code when you complete the database operation.
session.close();
Configuring JDBC Type 2 Driver for SQL/MX Database using
hibernate.properties
To complete the database operation in a Hibernate application using the JDBC Type 2 driver for
the SQL/MX database, complete the following steps:
1.
Specifying the JDBC Type 2 Driver for SQL/MX Database
2.
3.
4.
Defining the Hibernate Dialect for SQL/MX Database
5.
Opening a Session for Database Operation
6.
Specifying the Mapping Resources
7.
Specifying the JDBC Type 2 Driver for SQL/MX Database
To specify the JDBC Type 2 driver, enter
com.tandem.sqlmx.SQLMXDriver
as the JDBC Type
2 driver class for the SQL/MX database in the
hibernate.properties
file as shown:
hibernate.connection.driver_class_com.tandem.sqlmx.SQLMXDriver
320
Configuring Hibernate Applications on NonStop Systems