Top Description Fields Constructors Methods
org.hibernate.id

public Class TableGenerator

extends TransactionHelper
implements PersistentIdentifierGenerator, Configurable
Class Inheritance
All Implemented Interfaces
org.hibernate.id.Configurable, org.hibernate.id.PersistentIdentifierGenerator, org.hibernate.id.IdentifierGenerator
Known Direct Subclasses
org.hibernate.id.TableHiLoGenerator
Imports
java.io.Serializable, java.sql.Connection, .PreparedStatement, .ResultSet, .SQLException, .Types, java.util.Properties, org.slf4j.Logger, .LoggerFactory, org.hibernate.HibernateException, .LockMode, org.hibernate.cfg.ObjectNameNormalizer, org.hibernate.jdbc.util.FormatStyle, org.hibernate.dialect.Dialect, org.hibernate.engine.SessionImplementor, .TransactionHelper, org.hibernate.mapping.Table, org.hibernate.type.Type, org.hibernate.util.PropertiesHelper

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

Author
Gavin King
See Also
TableHiLoGenerator

Field Summary

Modifier and TypeField and Description
public static final String
COLUMN

The column parameter

private String
public static final String
DEFAULT_COLUMN_NAME

Default column name

public static final String
DEFAULT_TABLE_NAME

Default table name

private Type
private static final Logger
private String
public static final String
private String
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected IntegralDataTypeHolder
public void
configure(Type type, Properties
param values, keyed by parameter name
params
,
Dialect dialect)

Implements org.hibernate.id.Configurable.configure.

Configure this instance, given the value of parameters specified by the user as <param> elements.
public Serializable

Returns:

Prior to 3.5 this method returned an Integer. Since 3.5 it now returns a IntegralDataTypeHolder
doWorkInCurrentTransaction
(Connection
The sql connection to use.
conn
,
String
n/a
sql
)

Implements abstract org.hibernate.engine.TransactionHelper.doWorkInCurrentTransaction.

Get the next value.
public synchronized Serializable
generate(SessionImplementor session, Object
the entity or toplevel collection for which the id is being generated
object
)

Implements org.hibernate.id.IdentifierGenerator.generate.

Generate a new identifier.
protected IntegralDataTypeHolder
public Object
generatorKey()

Implements org.hibernate.id.PersistentIdentifierGenerator.generatorKey.

Return a key unique to the underlying database objects.
public String[]
sqlCreateStrings(Dialect
The dialect against which to generate the create command(s)
dialect
)

Implements org.hibernate.id.PersistentIdentifierGenerator.sqlCreateStrings.

The SQL required to create the underlying database objects.
public String[]
sqlDropStrings(Dialect
The dialect against which to generate the drop command(s)
dialect
)

Implements org.hibernate.id.PersistentIdentifierGenerator.sqlDropStrings.

The SQL required to remove the underlying database objects.
Inherited from org.hibernate.engine.TransactionHelper:
doWorkInNewTransaction

Field Detail

COLUMNback to summary
public static final String COLUMN

The column parameter

columnNameback to summary
private String columnName
DEFAULT_COLUMN_NAMEback to summary
public static final String DEFAULT_COLUMN_NAME

Default column name

DEFAULT_TABLE_NAMEback to summary
public static final String DEFAULT_TABLE_NAME

Default table name

identifierTypeback to summary
private Type identifierType
logback to summary
private static final Logger log
queryback to summary
private String query
TABLEback to summary
public static final String TABLE

Hides org.hibernate.id.PersistentIdentifierGenerator.TABLE.

The table parameter

tableNameback to summary
private String tableName
updateback to summary
private String update

Constructor Detail

TableGeneratorback to summary
public TableGenerator()

Method Detail

buildHolderback to summary
protected IntegralDataTypeHolder buildHolder()
configureback to summary
public void configure(Type type, Properties params, Dialect dialect)

Implements org.hibernate.id.Configurable.configure.

Doc from org.hibernate.id.Configurable.configure.

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:Properties

param values, keyed by parameter name

doWorkInCurrentTransactionback to summary
public Serializable doWorkInCurrentTransaction(Connection conn, String sql) throws SQLException

Implements abstract org.hibernate.engine.TransactionHelper.doWorkInCurrentTransaction.

Get the next value.

Parameters
conn:Connection

The sql connection to use.

sql:String

n/a

Returns:Serializable

Prior to 3.5 this method returned an Integer. Since 3.5 it now returns a IntegralDataTypeHolder

generateback to summary
public synchronized Serializable generate(SessionImplementor session, Object object)

Implements org.hibernate.id.IdentifierGenerator.generate.

Doc from org.hibernate.id.IdentifierGenerator.generate.

Generate a new identifier.

Parameters
object:Object

the entity or toplevel collection for which the id is being generated

Returns:Serializable

a new identifier

generateHolderback to summary
protected IntegralDataTypeHolder generateHolder(SessionImplementor session)
generatorKeyback to summary
public Object generatorKey()

Implements org.hibernate.id.PersistentIdentifierGenerator.generatorKey.

Doc from org.hibernate.id.PersistentIdentifierGenerator.generatorKey.

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

Returns:Object

Object an identifying key for this generator

sqlCreateStringsback to summary
public String[] sqlCreateStrings(Dialect dialect) throws HibernateException

Implements org.hibernate.id.PersistentIdentifierGenerator.sqlCreateStrings.

Doc from org.hibernate.id.PersistentIdentifierGenerator.sqlCreateStrings.

The SQL required to create the underlying database objects.

Parameters
dialect:Dialect

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

Returns:String[]

The create command(s)

Exceptions
HibernateException:
problem creating the create command(s)
sqlDropStringsback to summary
public String[] sqlDropStrings(Dialect dialect)

Implements org.hibernate.id.PersistentIdentifierGenerator.sqlDropStrings.

Doc from org.hibernate.id.PersistentIdentifierGenerator.sqlDropStrings.

The SQL required to remove the underlying database objects.

Parameters
dialect:Dialect

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

Returns:String[]

The drop command(s)