beautypg.com

Defining the connection url, Establishing the connection, Defining the hibernate dialect for sql/mx database – HP Integrity NonStop H-Series User Manual

Page 321: Opening a session for database operation, Configuring sessionfactory in your java program, Specifying the mapping resources

background image

Defining the Connection URL

After you have specified the JDBC Type 2 driver, enter the location of the SQL/MX server. URLs
referring to SQL/MX use the

jdbc: protocol

embedded within the URL.

To define the connection URL, enter

jdbc:sqlmx://

as the connection URL for the SQL/MX

database in the

hibernate.properties

file as shown:

hibernate.connection.url jdbc:sqlmx://

Establishing the Connection

If you plan to use the JDBC Type 2 driver, do not specify the username and password.

Add the properties for the username and password for your NonStop system in the

hibernate.properties

file 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:

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

2.

Creating a New Session from the

SessionFactory

in Java

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

the

JDBC Configuration

.

Specifying the Mapping Resources

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

Hibernate Framework Configurations for NonStop Systems

321

This manual is related to the following products: