Establishing the connection, Defining the hibernate dialect for sql/mx database, Opening a session for database operation – HP Integrity NonStop H-Series User Manual
Page 325: Configuring sessionfactory in your java program, Specifying the mapping resources
Establishing the Connection
To establish the connection, specify the username and password of your NonStop system in the
hibernate.properties
as shown.
hibernate.connection.username
hibernate.connection.password
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.properties
file as shown below.
hibernate.dialect org.hibernate.dialect.SqlmxDialect
This property allows Hibernate to generate SQL optimized for SQL/MX database.
Opening a Session for Database Operation
To open a new session for database transaction, complete the following steps:
1.
2.
Creating a New Session from the
Configuring
SessionFactory
in your Java Program
Add the following lines to your Java program to create Hibernate
SessionFactory
.
private SessionFactory factory;
...
...
...
public void databaseCon()
{
Configuration cfg = new Configuration();
factory = cfg.buildSessionFactory();
...
...
...
}
Creating a New Session from the
SessionFactory
in Java
Add the following lines to your Java program to create a new session from the
SessionFactory
:
Session s = factory.openSession();
This will create the session which will be used further to perform database operation.
NOTE:
To view the complete configuration snippet of the
hibernate.properties
file, see
the
.
Specifying the Mapping Resources
Specify all the mapping files (.hbm) in your Java program as shown:
Configuration cfg = new Configuration()
.addResource("
.addResource("
For example,
If the mapping file used in your application is
Item.hbm.xml
and
Bid.hbm.xml
, specify it
as shown:
Configuration cfg = new Configuration()
.addResource("Item.hbm.xml")
.addResource("Bid.hbm.xml");
The basic configuration is ready for you to perform database operation using Hibernate.
Hibernate Framework Configurations for NonStop Systems
325