Package org.hibernate.id
Class TableGenerator
java.lang.Object
org.hibernate.engine.TransactionHelper
org.hibernate.id.TableGenerator
- All Implemented Interfaces:
Configurable,IdentifierGenerator,PersistentIdentifierGenerator
- Direct Known 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 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- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe column parameterstatic final StringDefault column namestatic final StringDefault table namestatic final StringThe table parameterFields inherited from interface org.hibernate.id.IdentifierGenerator
ENTITY_NAMEFields inherited from interface org.hibernate.id.PersistentIdentifierGenerator
CATALOG, IDENTIFIER_NORMALIZER, PK, SCHEMA, SQL_STATEMENT_LOGGER, TABLES -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected IntegralDataTypeHoldervoidconfigure(Type type, Properties params, Dialect dialect) Configure this instance, given the value of parameters specified by the user as <param> elements.doWorkInCurrentTransaction(Connection conn, String sql) Get the next value.generate(SessionImplementor session, Object object) Generate a new identifier.protected IntegralDataTypeHoldergenerateHolder(SessionImplementor session) 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.Methods inherited from class org.hibernate.engine.TransactionHelper
doWorkInNewTransaction
-
Field Details
-
COLUMN
The column parameter- See Also:
-
DEFAULT_COLUMN_NAME
Default column name- See Also:
-
TABLE
The table parameter- See Also:
-
DEFAULT_TABLE_NAME
Default table name- See Also:
-
-
Constructor Details
-
TableGenerator
public TableGenerator()
-
-
Method Details
-
configure
Description copied from interface:ConfigurableConfigure this instance, given the value of parameters specified by the user as <param> elements. This method is called just once, following instantiation.- Specified by:
configurein interfaceConfigurable- Parameters:
params- param values, keyed by parameter name
-
generate
Description copied from interface:IdentifierGeneratorGenerate a new identifier.- Specified by:
generatein interfaceIdentifierGenerator- Parameters:
session-object- the entity or toplevel collection for which the id is being generated- Returns:
- a new identifier
-
generateHolder
-
sqlCreateStrings
Description copied from interface:PersistentIdentifierGeneratorThe SQL required to create the underlying database objects.- Specified by:
sqlCreateStringsin interfacePersistentIdentifierGenerator- Parameters:
dialect- The dialect against which to generate the create command(s)- Returns:
- The create command(s)
- Throws:
HibernateException- problem creating the create command(s)
-
sqlDropStrings
Description copied from interface:PersistentIdentifierGeneratorThe SQL required to remove the underlying database objects.- Specified by:
sqlDropStringsin interfacePersistentIdentifierGenerator- Parameters:
dialect- The dialect against which to generate the drop command(s)- Returns:
- The drop command(s)
-
generatorKey
Description copied from interface:PersistentIdentifierGeneratorReturn a key unique to the underlying database objects. Prevents us from trying to create/remove them multiple times.- Specified by:
generatorKeyin interfacePersistentIdentifierGenerator- Returns:
- Object an identifying key for this generator
-
doWorkInCurrentTransaction
Get the next value.- Specified by:
doWorkInCurrentTransactionin classTransactionHelper- Parameters:
conn- The sql connection to use.sql- n/a- Returns:
- Prior to 3.5 this method returned an
Integer. Since 3.5 it now returns aIntegralDataTypeHolder - Throws:
SQLException
-
buildHolder
-