java.lang.Object | ||
↳ | org.hibernate.engine.TransactionHelper | |
↳ | org.hibernate.id.enhanced.TableGenerator |
An enhanced version of table-based id generation.
Unlike the simplistic legacy one (which, btw, was only ever intended for subclassing support) we "segment" the table into multiple values. Thus a single table can actually serve as the persistent storage for multiple independent generators. One approach would be to segment the values by the name of the entity for which we are performing generation, which would mean that we would have a row in the generator table for each entity name. Or any configuration really; the setup is very flexible. In this respect it is very similar to the legacyMultipleHiLoPerTableGenerator
in terms of the
underlying storage structure (namely a single table capable of holding
multiple generator values). The differentiator is, as with
SequenceStyleGenerator
as well, the externalized notion
of an optimizer.
NOTE that by default we use a single row for all generators (based
on DEF_SEGMENT_VALUE
). The configuration parameter
CONFIG_PREFER_SEGMENT_PER_ENTITY
can be used to change that to
instead default to using a row for each entity name.
Configuration parameters:
NAME | DEFAULT | DESCRIPTION |
TABLE_PARAM |
DEF_TABLE |
The name of the table to use to store/retrieve values |
VALUE_COLUMN_PARAM |
DEF_VALUE_COLUMN |
The name of column which holds the sequence value for the given segment |
SEGMENT_COLUMN_PARAM |
DEF_SEGMENT_COLUMN |
The name of the column which holds the segment key |
SEGMENT_VALUE_PARAM |
DEF_SEGMENT_VALUE |
The value indicating which segment is used by this generator; refers to values in the SEGMENT_COLUMN_PARAM column |
SEGMENT_LENGTH_PARAM |
DEF_SEGMENT_LENGTH |
The data length of the SEGMENT_COLUMN_PARAM column; used for schema creation |
INITIAL_PARAM |
DEFAULT_INITIAL_VALUE |
The initial value to be stored for the given segment |
INCREMENT_PARAM |
DEFAULT_INCREMENT_SIZE |
The increment size for the underlying segment; see the discussion on Optimizer for more details. |
OPT_PARAM |
depends on defined increment size | Allows explicit definition of which optimization strategy to use |
[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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Configure this instance, given the value of parameters
specified by the user as <param> elements.
| |||||||||||
The work to be done
| |||||||||||
Generate a new identifier.
| |||||||||||
Return a key unique to the underlying database objects.
| |||||||||||
Type mapping for the identifier.
| |||||||||||
The amount of increment to use.
| |||||||||||
The initial value to use when we find no previous state in the
generator table corresponding to our sequence.
| |||||||||||
The optimizer being used by this generator.
| |||||||||||
The name of the column in which we store the segment to which each row
belongs.
| |||||||||||
The value in
segment column which
corresponding to this generator instance. | |||||||||||
The size of the
segment column in the
underlying table. | |||||||||||
Getter for property 'tableAccessCount'.
| |||||||||||
The name of the table in which we store this generator's persistent state.
| |||||||||||
The name of the column in which we store our persistent generator value.
| |||||||||||
The SQL required to create the underlying database objects.
| |||||||||||
The SQL required to remove the underlying database objects.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Used in the cases where
determineSegmentValue(Properties) is unable to
determine the value to use. | |||||||||||
Determine the table name to use for the generator values.
| |||||||||||
Determine the name of the column used to indicate the segment for each
row.
| |||||||||||
Determine the size of the
segment column
Called during configuration . | |||||||||||
Determine the segment value corresponding to this generator instance.
| |||||||||||
Determine the name of the column in which we will store the generator persistent value.
|
[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
|
Configure this instance, given the value of parameters specified by the user as <param> elements. This method is called just once, following instantiation.
params | param values, keyed by parameter name |
---|
MappingException |
---|
The work to be done
SQLException |
---|
Generate a new identifier.
obj | the entity or toplevel collection for which the id is being generated |
---|
Return a key unique to the underlying database objects. Prevents us from trying to create/remove them multiple times.
Type mapping for the identifier.
The amount of increment to use. The exact implications of this
depends on the optimizer
being used.
The initial value to use when we find no previous state in the generator table corresponding to our sequence.
The optimizer being used by this generator.
The name of the column in which we store the segment to which each row belongs. The value here acts as PK.
The value in segment column
which
corresponding to this generator instance. In other words this value
indicates the row in which this generator instance will store values.
The size of the segment column
in the
underlying table.
Getter for property 'tableAccessCount'. Only really useful for unit test assertions.
The name of the table in which we store this generator's persistent state.
The name of the column in which we store our persistent generator value.
The SQL required to create the underlying database objects.
dialect | The dialect against which to generate the create command(s) |
---|
HibernateException |
---|
The SQL required to remove the underlying database objects.
dialect | The dialect against which to generate the drop command(s) |
---|
HibernateException |
---|
Used in the cases where determineSegmentValue(Properties)
is unable to
determine the value to use.
params | The params supplied in the generator config (plus some standard useful extras). |
---|
Determine the table name to use for the generator values.
Called duringconfiguration
.params | The params supplied in the generator config (plus some standard useful extras). |
---|---|
dialect | The dialect in effect |
Determine the name of the column used to indicate the segment for each row. This column acts as the primary key.
Called duringconfiguration
.params | The params supplied in the generator config (plus some standard useful extras). |
---|---|
dialect | The dialect in effect |
Determine the size of the segment column
configuration
.params | The params supplied in the generator config (plus some standard useful extras). |
---|
Determine the segment value corresponding to this generator instance.
Called duringconfiguration
.params | The params supplied in the generator config (plus some standard useful extras). |
---|
Determine the name of the column in which we will store the generator persistent value.
Called duringconfiguration
.params | The params supplied in the generator config (plus some standard useful extras). |
---|---|
dialect | The dialect in effect |