Top Description Constructors Methods
org.hibernate.id

public Class IdentityGenerator

extends Object
implements PostInsertIdentifierGenerator, BulkInsertionCapableIdentifierGenerator, StandardGenerator
Class Inheritance
All Implemented Interfaces
org.hibernate.id.factory.spi.StandardGenerator, org.hibernate.id.BulkInsertionCapableIdentifierGenerator, org.hibernate.generator.Generator, java.io.Serializable, org.hibernate.id.PostInsertIdentifierGenerator, org.hibernate.id.Configurable, org.hibernate.generator.OnExecutionGenerator
Imports
org.hibernate.dialect.Dialect, org.hibernate.id.factory.spi.StandardGenerator, org.hibernate.generator.OnExecutionGenerator, org.hibernate.id.insert.BasicSelectingDelegate, .InsertGeneratedIdentifierDelegate, .InsertReturningDelegate

An OnExecutionGenerator that handles IDENTITY/"autoincrement" columns on those databases which support them.

Delegates to the org.hibernate.dialect.identity.IdentityColumnSupport provided by the dialect.

The actual work involved in retrieving the primary key value is the job of a org.hibernate.id.insert.InsertGeneratedIdentifierDelegate, either:

Implementation Note

This also implements the identity generation type in hbm.xml mappings.

Author
Christoph Sturm
See Also
jakarta.persistence.GenerationType#IDENTITY, org.hibernate.dialect.identity.IdentityColumnSupport, org.hibernate.id.insert.InsertGeneratedIdentifierDelegate

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public InsertGeneratedIdentifierDelegate
getGeneratedIdentifierDelegate(PostInsertIdentityPersister persister)

Overrides default org.hibernate.generator.OnExecutionGenerator.getGeneratedIdentifierDelegate.

The InsertGeneratedIdentifierDelegate used to retrieve the generated value if this object is an identifier generator.
public String[]
getReferencedColumnValues(Dialect
The SQL dialect, allowing generation of an expression in dialect-specific SQL.
dialect
)

Implements org.hibernate.generator.OnExecutionGenerator.getReferencedColumnValues.

A SQL expression indicating how to calculate the generated values when the mapped columns are included in the SQL statement.
public boolean
referenceColumnsInSql(Dialect dialect)

Implements org.hibernate.generator.OnExecutionGenerator.referenceColumnsInSql.

Determines if the columns whose values are generated are included in the column list of the SQL insert or update statement.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

IdentityGeneratorback to summary
public IdentityGenerator()

Method Detail

getGeneratedIdentifierDelegateback to summary
public InsertGeneratedIdentifierDelegate getGeneratedIdentifierDelegate(PostInsertIdentityPersister persister)

Overrides default org.hibernate.generator.OnExecutionGenerator.getGeneratedIdentifierDelegate.

Doc from org.hibernate.generator.OnExecutionGenerator.getGeneratedIdentifierDelegate.

The InsertGeneratedIdentifierDelegate used to retrieve the generated value if this object is an identifier generator.

This is ignored by org.hibernate.metamodel.mapping.internal.GeneratedValuesProcessor, which handles multiple generators at once. So if this object is not an identifier generator, this method is never called.

Note that this method arguably breaks the separation of concerns between the generator and coordinating code, by specifying how the generated value should be retrieved.

The problem solved here is: we want to obtain an insert-generated primary key. But, sadly, without already knowing the primary key, there's no completely-generic way to locate the just-inserted row to obtain it.

We need one of the following things:

Alternatively, if the generated id is an identity/"autoincrement" column, we can take advantage of special platform-specific functionality to retrieve it. Taking advantage of the specialness of identity columns is the job of one particular implementation: org.hibernate.id.IdentityGenerator. And the need for customized behavior for identity columns is the reason why this layer-breaking method exists.

Annotations
@Override
getReferencedColumnValuesback to summary
public String[] getReferencedColumnValues(Dialect dialect)

Implements org.hibernate.generator.OnExecutionGenerator.getReferencedColumnValues.

Doc from org.hibernate.generator.OnExecutionGenerator.getReferencedColumnValues.

A SQL expression indicating how to calculate the generated values when the mapped columns are included in the SQL statement. The SQL expressions might be:

  • function calls like current_timestamp or nextval('mysequence'), or
  • syntactic markers like default.
Parameters
dialect:Dialect

The SQL dialect, allowing generation of an expression in dialect-specific SQL.

Returns:String[]

The column value to be used in the generated SQL statement.

Annotations
@Override
referenceColumnsInSqlback to summary
public boolean referenceColumnsInSql(Dialect dialect)

Implements org.hibernate.generator.OnExecutionGenerator.referenceColumnsInSql.

Doc from org.hibernate.generator.OnExecutionGenerator.referenceColumnsInSql.

Determines if the columns whose values are generated are included in the column list of the SQL insert or update statement. For example, this method should return:

Returns:boolean

true if the column is included in the column list of the SQL statement.

Annotations
@Override