public class

MultipleHiLoPerTableGenerator

extends TransactionHelper
implements Configurable PersistentIdentifierGenerator
java.lang.Object
   ↳ org.hibernate.engine.TransactionHelper
     ↳ org.hibernate.id.MultipleHiLoPerTableGenerator

Class Overview

A hilo IdentifierGenerator that returns a Long, constructed using a hi/lo algorithm. 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 the user is supplying connections. In this case a SequenceHiLoGenerator would be a better choice (where supported).

A hilo IdentifierGenerator that uses a database table to store the last generated values. A table can contains several hi values. They are distinct from each other through a key

This implementation is not compliant with a user connection

Allowed parameters (all of them are optional):

  • table: table name (default hibernate_sequences)
  • primary_key_column: key column name (default sequence_name)
  • value_column: hi value column name(default sequence_next_hi_value)
  • primary_key_value: key value for the current entity (default to the entity's primary table name)
  • primary_key_length: length of the key column in DB represented as a varchar (default to 255)
  • max_lo: max low value before increasing hi (default to Short.MAX_VALUE)

Summary

Constants
String DEFAULT_TABLE
String ID_TABLE
String MAX_LO
String PK_COLUMN_NAME
String PK_LENGTH_NAME
String PK_VALUE_NAME
String VALUE_COLUMN_NAME
[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
MultipleHiLoPerTableGenerator()
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)
The work to be done
synchronized Serializable generate(SessionImplementor session, Object obj)
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.
[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 DEFAULT_TABLE

Constant Value: "hibernate_sequences"

public static final String ID_TABLE

Constant Value: "table"

public static final String MAX_LO

Constant Value: "max_lo"

public static final String PK_COLUMN_NAME

Constant Value: "primary_key_column"

public static final String PK_LENGTH_NAME

Constant Value: "primary_key_length"

public static final String PK_VALUE_NAME

Constant Value: "primary_key_value"

public static final String VALUE_COLUMN_NAME

Constant Value: "value_column"

Public Constructors

public MultipleHiLoPerTableGenerator ()

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)

The work to be done

Throws
SQLException

public synchronized Serializable generate (SessionImplementor session, Object obj)

Generate a new identifier.

Parameters
obj 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)