org.hibernate.id

Class TableGenerator

Implemented Interfaces:
Configurable, IdentifierGenerator, PersistentIdentifierGenerator
Known Direct Subclasses:
TableHiLoGenerator

public class TableGenerator
extends TransactionHelper
implements PersistentIdentifierGenerator, Configurable

An IdentifierGenerator that uses a database table to store the last generated value. It is not intended that applications use this strategy directly. However, it may be used to build other (efficient) strategies. The returned type is Integer.

The hi value MUST be fetched in a seperate transaction to the Session transaction so the generator must be able to obtain a new connection and commit it. Hence this implementation may not be used when Hibernate is fetching connections when the user is supplying connections.

The returned value is of type integer.

Mapping parameters supported: table, column
Author:
Gavin King
See Also:
TableHiLoGenerator

Field Summary

static String
COLUMN
The column parameter
static String
DEFAULT_COLUMN_NAME
Default column name
static String
DEFAULT_TABLE_NAME
Default table name
static String
TABLE
The table parameter

Fields inherited from interface org.hibernate.id.IdentifierGenerator

ENTITY_NAME

Fields inherited from interface org.hibernate.id.PersistentIdentifierGenerator

CATALOG, PK, SCHEMA, SQL_STATEMENT_LOGGER, TABLE, TABLES

Method Summary

void
configure(Type type, Properties params, Dialect dialect)
Configure this instance, given the value of parameters specified by the user as <param> elements.
Serializable
doWorkInCurrentTransaction(Connection conn, String sql)
Serializable
generate(SessionImplementor session, Object object)
Generate a new identifier.
Object
generatorKey()
String[]
sqlCreateStrings(Dialect dialect)
String[]
sqlDropStrings(Dialect dialect)

Methods inherited from class org.hibernate.engine.TransactionHelper

doWorkInCurrentTransaction, doWorkInNewTransaction

Field Details

COLUMN

public static final String COLUMN
The column parameter

DEFAULT_COLUMN_NAME

public static final String DEFAULT_COLUMN_NAME
Default column name

DEFAULT_TABLE_NAME

public static final String DEFAULT_TABLE_NAME
Default table name

TABLE

public static final String TABLE
The table parameter

Method Details

configure

public void configure(Type type,
                      Properties params,
                      Dialect dialect)
Configure this instance, given the value of parameters specified by the user as <param> elements. This method is called just once, following instantiation.
Specified by:
configure in interface Configurable
Parameters:
params - param values, keyed by parameter name

doWorkInCurrentTransaction

public Serializable doWorkInCurrentTransaction(Connection conn,
                                               String sql)
            throws SQLException
Overrides:
doWorkInCurrentTransaction in interface TransactionHelper

generate

public Serializable generate(SessionImplementor session,
                             Object object)
            throws HibernateException
Generate a new identifier.
Specified by:
generate in interface IdentifierGenerator
Parameters:
session -
object - the entity or toplevel collection for which the id is being generated
Returns:
a new identifier

generatorKey

public Object generatorKey()
Specified by:
generatorKey in interface PersistentIdentifierGenerator

sqlCreateStrings

public String[] sqlCreateStrings(Dialect dialect)
            throws HibernateException
Specified by:
sqlCreateStrings in interface PersistentIdentifierGenerator

sqlDropStrings

public String[] sqlDropStrings(Dialect dialect)
Specified by:
sqlDropStrings in interface PersistentIdentifierGenerator