Defining the hibernate dialect for sql/mx database, Opening a session for database operation, Configuring sessionfactory in your java program – HP Integrity NonStop J-Series User Manual

Page 184: Specifying the mapping resources, Closing the session

Advertising
background image

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:

hibernate.dialect org.hibernate.dialect.SqlmxDialect

This dialect file 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.

“Configuring SessionFactory in your Java Program” (page 184)

2.

“Creating a New Session from the SessionFactory in Java” (page 184)

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 in your application to perform database
operation.

NOTE:

To view the complete configuration snippet of the hibernate.properties file, see

“JDBC Configuration” (page 227)

.

Specifying the Mapping Resources

Specify all the mapping files (.hbm) in your Java program as shown.

Configuration cfg = new Configuration()
.addResource("Name of mapping file#1")
.addResource("Name of mapping file#2");

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.

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.

184 Configuring Hibernate Applications on NonStop Systems

Advertising
This manual is related to the following products: