public class

TableGenerator

extends TransactionHelper
implements Configurable PersistentIdentifierGenerator
java.lang.Object
   ↳ org.hibernate.engine.TransactionHelper
     ↳ org.hibernate.id.TableGenerator
Known Direct Subclasses

Class Overview

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 any supported by IntegralDataTypeHolder

The value MUST be fetched in a separate transaction from that of the main session transaction so the generator must be able to obtain a new connection and commit it. Hence this implementation may only be used when Hibernate is fetching connections, not when the user is supplying connections.

Again, the return types supported here are any of the ones supported by IntegralDataTypeHolder. This is new as of 3.5. Prior to that this generator only returned Integer values.

Mapping parameters supported: table, column

Summary

Constants
String COLUMN The column parameter
String DEFAULT_COLUMN_NAME Default column name
String DEFAULT_TABLE_NAME Default table name
String TABLE The table parameter
[Expand]
Inherited Constants
From interface org.hibernate.id.IdentifierGenerator
From interface org.hibernate.id.PersistentIdentifierGenerator
[Expand]
Inherited Fields
From interface org.hibernate.id.PersistentIdentifierGenerator
Public Constructors
TableGenerator()
Public Methods
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)
Get the next value.
synchronized Serializable generate(SessionImplementor session, Object object)
Generate a new identifier.
Object generatorKey()
Return a key unique to the underlying database objects.
String[] sqlCreateStrings(Dialect dialect)
The SQL required to create the underlying database objects.
String[] sqlDropStrings(Dialect dialect)
The SQL required to remove the underlying database objects.
Protected Methods
IntegralDataTypeHolder buildHolder()
IntegralDataTypeHolder generateHolder(SessionImplementor session)
[Expand]
Inherited Methods
From class org.hibernate.engine.TransactionHelper
From class java.lang.Object
From interface org.hibernate.id.Configurable
From interface org.hibernate.id.IdentifierGenerator
From interface org.hibernate.id.PersistentIdentifierGenerator

Constants

public static final String COLUMN

The column parameter

Constant Value: "column"

public static final String DEFAULT_COLUMN_NAME

Default column name

Constant Value: "next_hi"

public static final String DEFAULT_TABLE_NAME

Default table name

Constant Value: "hibernate_unique_key"

public static final String TABLE

The table parameter

Constant Value: "table"

Public Constructors

public TableGenerator ()

Public Methods

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.

Parameters
params param values, keyed by parameter name

public Serializable doWorkInCurrentTransaction (Connection conn, String sql)

Get the next value.

Parameters
conn The sql connection to use.
sql n/a
Returns
Throws
SQLException

public synchronized Serializable generate (SessionImplementor session, Object object)

Generate a new identifier.

Parameters
object the entity or toplevel collection for which the id is being generated
Returns
  • a new identifier

public Object generatorKey ()

Return a key unique to the underlying database objects. Prevents us from trying to create/remove them multiple times.

Returns
  • Object an identifying key for this generator

public String[] sqlCreateStrings (Dialect dialect)

The SQL required to create the underlying database objects.

Parameters
dialect The dialect against which to generate the create command(s)
Returns
  • The create command(s)

public String[] sqlDropStrings (Dialect dialect)

The SQL required to remove the underlying database objects.

Parameters
dialect The dialect against which to generate the drop command(s)
Returns
  • The drop command(s)

Protected Methods

protected IntegralDataTypeHolder buildHolder ()

protected IntegralDataTypeHolder generateHolder (SessionImplementor session)