Closing the session, Database transaction management – HP Integrity NonStop H-Series User Manual

Page 326

Advertising
background image

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();

Database Transaction Management

Hibernate works in any environment that uses JTA, in fact, we recommend to use JTA whenever
possible as it is the standard Java transaction interface. You get JTA built-in with all J2EE/JEE
application servers, and each datasource you use in such a container is automatically handled
by a JTA TransactionManager.

NOTE:

NonStop Server for Java supports transactions by means of the NonStop Server for JTA,
which is an implementation of the Sun Microsystems JTA.

NonStop Server for JTA implements the package,

javax.transaction

.

NonStop Server for Java includes the JTA package

com.tandem.jta

.

Configurations using JTA

The application code must implement JTA user transaction by using JTAFactory provided with
the NonStop Server for Java Transaction API package

com.tandem.jta

. This can be achieved

by following the below given steps:

1.

Define a JTA user transaction.

javax.transaction.UserTransaction tx = null;

2.

Initialize the user transaction.

tx = com.tandem.jta.JTAFactory.getUserTransaction();

3.

Begin the transaction.

tx.begin();

4.

Commit or rollback the transaction depending upon the status of the operations performed.

tx.commit();

or

tx.rollback();

Configurations using JDBC

To use JDBC Transaction Manager, complete the following steps:

1.

Open the session.

Session session = factory.openSession();

2.

Initialize the user transaction.

Transaction tx = null;

3.

Begin the transaction.

tx = session.beginTransaction();

4.

Perform the database operation.

session.load(...);
session.persist(...);

5.

Commit or rollback the transaction depending upon the status of the operations performed.

tx.commit();

or

326

Configuring Hibernate Applications on NonStop Systems

Advertising
This manual is related to the following products: