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

Page 182: Specifying the mapping resources, Opening a session for database operation, Opening a session

Advertising
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 and have the server host, port number embedded
within the URL.

To define the connection URL, enter the connection URL as jdbc:sqlmx:// for the SQL/MX
database in the hibernate.cfg.xml file under the <session-factory> tag as shown:

<property name="connection.url">jdbc:sqlmx://</property>

Establishing the Connection

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

Add the following syntax in the hibernate.cfg.xml file under the <session-factory> tag
as shown:

<property name="connection.username"></property>
<property name="connection.password"></property>

Defining the Hibernate Dialect for SQL/MX Database

Enter org.hibernate.dialect.SqlmxDialect as the Hibernate dialect class name for
SQL/MX database, in the hibernate.cfg.xml file under the <session-factory> tag.

<property name="dialect">
org.hibernate.dialect.SqlmxDialect
</property>

This dialect file allows Hibernate to generate SQL that is optimized for the SQL/MX database.

Specifying the Mapping Resources

Specify all the mapping files (.hbm) in the <mapping resource> tag as shown:

<!-- Mapping files -->
<mapping resource="<Name of the .hbm file>" />

For example:

If the mapping file used in your application is Employee.hbm.xml, specify it as shown:

<!-- Mapping files -->
<mapping resource="Employee.hbm.xml" />

The basic configuration is ready for you to perform database operation using Hibernate.

Opening a Session for Database Operation

To open a new session for database transaction, complete the following steps:

1.

“Configuring SessionFactory in the hibernate.cfg.xml File” (page 182)

2.

“Creating a New Session from the SessionFactory in your Java Program” (page 183)

Configuring SessionFactory in the hibernate.cfg.xml File

Add the following lines in the hibernate.cfg.xml file to configure the Hibernate
SessionFactory

.

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
...
...
...
...
...

182

Configuring Hibernate Applications on NonStop Systems

Advertising
This manual is related to the following products: