Hibernate Connection Guide

Introduction


This document describes Altibase connection method in Hibernate + Spring environment.

Altibase provides several Hibernate related sample codes including AltibaseDialect class sample in attached Example directory.

The attached samples in the Example directory use Hibernate 3.6.0, Spring Framework 2.5.6, Altibase 5.3.3

This guide is up to date as of ALTIBASE HDB version 6.5.

Altibase Hibernate Connection Quick Guide


This chapter includes quick guide for Altibase Hibernate connection.

Hibernate-mapping XML sample

Hibernate-mapping XML file has mapping information between a DB table and a Java Object.

This is a sample hibernate-mapping XML which has mapping information between person table and Person class. You can find this file in attached Example directory. (~\Example\workspace\AltibaseConnection\src\Person.hbm.xml)

1. person

Including AltibaseDialect class at Hibernate jar file

Hibernate does not provide Altibase dialect class. You have to include Altibase dialect class at Hibernate jar(ex.hibernate3.jar) file to use Altibase properly.

Altibase does not provide Altibase dialect class officially but provide Altibase dialect sample for reference purpose. You can find AltibaseDialect.java and AltibaseDialect.class  sample at attached Example directory.

Followings are the method to include AltibaseDialect.class file at Hibernate jar file.

  1. Uncompress Hibernate jar file.
  2. Locate AltibaseDialect.class file at ~\hibernate\dialect directory.
    ex) C:\hibernate-distribution-3.6.0.Final\hibernate3\org\hibernate\dialect
  3. Make a jar file using jar command.
    ex) jar -cvfm hibernate3.jar META-INF\MANIFEST.MF

Altibase JDBC Driver

Altibase JDBC driver is Altibase.jar file. Altibase.jar exists at lib directory of Altibase installation home directory. ($Altibase_HOME/lib)

Hibernate-configuration XML sample

Hibernate-configuration file specifies dialect class, connection properties and hibernate-mapping file.

This is a hibernate-configuration sample.

You can find this file in attached Example directory. (~\Example\workspace\AltibaseConnection\src\Hibernate.cfg.xml)

2. hibernate config

Application sample

This is an application sample for modifying person table data.

You can find this file in attached Example directory. (~\Example\workspace\AltibaseConnection\src\PersonApp.java)

3. personapp

Connection FailOver sample

You can set FailOver at hibernate-configuration file’s connection.url property.

This is a FailOver sample.

You can find this file in attached Example directory.

(~\Example\workspace\FailoverSample\src\Hibernate.cfg.xml)anual in support.altibase.com.

4. hibernate config_2

You can find detailed information of FailOver properties at JDBC User’s Manual in support.altibase.com.

Hibernate + Spring + Altibase


This chapter explains two different ways for connecting Altibase using Hibernate + Spring.

Using dataSource setting

You can find this file in attached Example directory.

(~\Example\workspace\SpringAltibaseConnection1\src\applicationContext.xml)

5. application context
You can use connection pool feature using this setting.

6. setting

Using hibernateProperties setting

You can find this file in attached Example directory.

(~\Example\workspace\SpringAltibaseConnection2\src\applicationContext.xml)

7. application context_2

Other considerations for Altibase + Hibernate


OTHER CONSIDERATIONS FOR ALTIBASE HIBERNATE

This chapter describes various considerations for Altibase connection of Hibernate.

Hibernate transaction handling

Hibernate transaction can be handled by Session class’s beginTransaction() method and Transaction class’s commit()/rollback() methods.

You can find this file in attached Example directory. (~\Example\workspace\AltibaseConnection\src\PersonApp.java)

8. personapp_2

Hibernate LOB data handling

This is a hibernate-mapping file sample for LOB data handling.

You can find this file in attached Example directory. (~\Example\workspace\LobSample\src\LobSample.hbm.xml)

9. Lobsample
You have to call beginTransaction() method before handling LOB data.

If you do not call beginTransaction() method when handling LOB data, following errors can occur.

  1. Retrieving LOB data
    null value return or “java.sql.SQLException: [0]:LobLocator can not span the transaction 101858625.”
  2. Saving LOB data
    “java.sql.SQLException: [0]: Connection is in autocommit mode. One can not operate on LOB datas with autocommit mode on.”

This is an application sample for LOB data handling.

You can find this file in attached Example directory. (~\Example\workspace\LobSample\src\LobApp.java)

10. Lobapp

Stored Procedure/Function call

This is a sample for Stored Procedure/Function creation in Altibase.

You can find this file in attached Example directory. (~\Example\workspace\ProcedureSample\src\create_procedure.sql)

11. create procedure
This is an application sample for Stored Procedure/Function call.

You can find this file in attached Example directory. (~\Example\workspace\ProcedureSample\src\ProcedureApp.java)

12. procedure App

NativeSQL execution

MOVE SQL syntax is an Altibase native SQL syntax.

Followings are samples for using DBMS specific SQL syntax.

You can find this file in attached Example directory.

(~\Example\workspace\NativeSQL\src\NativeSQL.hbm.xml)

13. native sql
You can find this file in attached Example directory.

(~\Example\workspace\NativeSQL\src\NativeSQLApp.java)

14. NativeSQLapp

Paging problem

When building a bulletin board application using Hibernate and Altibase, if last page is not displayed properly then following method can be used.

You can find this file in attached Example directory.

(~\Example\AltibaseDialect.java)

15. AltibaseDialect

Copyright ⓒ 2000~2016 Altibase Corporation. All Rights Reserved.

These documents are for informational purposes only. These information contained herein is not warranted to be error-free and is subject to change without notice. Decisions pertaining to Altibase’s product characteristics, features and development roadmap are at the sole discretion of Altibase. Altibase may own related patents, trademarks, copyright or other intellectual property rights of products and/or features discussed in this document.