Closing the session, Defining the connection url, Establishing the connection – HP Integrity NonStop J-Series User Manual

Page 183

Advertising
background image

</session-factory>
</hibernate-configuration>

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

“JDBC

Configuration” (page 227)

.

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” (page 183)

2.

“Defining the Connection URL” (page 183)

3.

“Establishing the Connection” (page 183)

4.

“Defining the Hibernate Dialect for SQL/MX Database” (page 184)

5.

“Opening a Session for Database Operation” (page 184)

6.

“Specifying the Mapping Resources” (page 184)

7.

“Closing the Session” (page 184)

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

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

Hibernate Framework Configurations for NonStop Systems 183

Advertising
This manual is related to the following products: