beautypg.com

HP Integrity NonStop J-Series User Manual

Page 96

background image

All generators implement the interface org.hibernate.id.IdentifierGenerator. Some
applications may have their own specialized implementations; however, Hibernate provides a
range of built-in implementations, such as increment, identity, sequence, hilo, Seqhilo, uuid, guid,
native, assigned, select, foreign, and sequence-identity. You can use any of the built-in
implementations except sequence, guid, native, and sequence-identity.

CAUTION:

When using any of the Hibernate built-in generators (not dependent on underlying

database), use your judgment to select the correct id generator, since the built-in generators are
not yet certified to generate unique value in all circumstances on NonStop TSMP environment.

You can choose any of the ID generators that leverage the ID generation mechanism provided by
the underlying database.

NOTE:

IDENTITY column feature is supported from SQL/MX 3.1 version onwards.

SQL/MX does not support SEQUENCE generators and GUIDs.

In general, hibernate allows mapping of Plain Old Java Objects (POJO) to tables and its attributes
to columns in an xml file. This file also captures the mapping between POJO fields to table column.
When you define this mapping, you can specify a generator class when a column is of type
IDENTITY.

When you define the mapping between the SQL table and POJO in the hbm.xml file, you can
specify a generator for the id column as follows:



OR



When the generator class is specified as identity, Hibernate will invoke the dialect methods internally
and treats the mapped table column to person_id field in the POJO as an IDENTITY column.

When the generator class is specified as
org.hibernate.dialect.SqlMxIdentityGenerator

, the dialect returns an appropriate

error when it is used with an SQL/MX version that does not support IDENTITY column. It has a
built-in mechanism to detect the SQL/MX version.

NOTE:

The org.hibernate.dialect.SqlMxIdentityGenerator generator class supports

only the update operation and not the create operation.

The following use cases show the typical errors that may be returned when this mapping is not
specified.

Use case 1

When a table does not contain identity columns and the hibernate mapping contains the generator
class as “identity” or "org.hibernate.dialect.SqlMxIdentityGenerator “, then the dialect returns the
following errors that are captured in the log:

org.hibernate.exception.GenericJDBCException: could not insert:

Caused by: com.tandem.t4jdbc.SQLMXException: *** ERROR[4024] Column ID has no default
value, so it must be explicitly specified in the insert column list.

Use case 2

96

Hibernate Framework

This manual is related to the following products: