Top Description Fields Methods
org.hibernate.id

public Interface IdentifierGenerator

extends BeforeExecutionGenerator, ExportableProducer, Configurable
Known Direct Subinterfaces
org.hibernate.id.OptimizableGenerator
Known Direct Implementers
org.hibernate.id.IncrementGenerator, org.hibernate.id.UUIDGenerator, org.hibernate.id.AbstractUUIDGenerator, org.hibernate.id.Assigned, org.hibernate.id.CompositeNestedGeneratedValueGenerator, org.hibernate.id.ForeignGenerator, org.hibernate.id.GUIDGenerator
Imports
java.util.EnumSet, .Properties, org.hibernate.HibernateException, .MappingException, org.hibernate.boot.model.relational.Database, .ExportableProducer, .SqlStringGenerationContext, org.hibernate.engine.spi.SharedSessionContractImplementor, org.hibernate.generator.EventType, .EventTypeSets, .BeforeExecutionGenerator, org.hibernate.service.ServiceRegistry, org.hibernate.type.Type

A classic extension point from the very earliest days of Hibernate, this interface is no longer the only way to generate identifiers. Any BeforeExecutionGenerator with timing EventTypeSets#INSERT_ONLY may now be used.

This interface extends BeforeExecutionGenerator with some additional machinery for configuration, and for caching generated SQL.

Any identifier generator, including a generator which directly implements BeforeExecutionGenerator, may also implement ExportableProducer. For the sake of convenience, PersistentIdentifierGenerator extends ExportableProducer, in case the implementation needs to export objects to the database as part of the process of schema export.

The configure(Type, Properties, ServiceRegistry) method accepts a properties object containing named values. These include:

Instances of IdentifierGenerator are usually created and configured by the org.hibernate.id.factory.IdentifierGeneratorFactory service. It's not usually correct to use an IdentifierGenerator with the org.hibernate.annotations.IdGeneratorType meta-annotation.

Author
Gavin King
See Also
PostInsertIdentifierGenerator, PersistentIdentifierGenerator

Field Summary

Modifier and TypeField and Description
public static final String
CONTRIBUTOR_NAME

The contributor that contributed this generator

public static final String
ENTITY_NAME

The configuration parameter holding the entity name

public static final String
GENERATOR_NAME

The configuration parameter holding the name of this identifier generator.

public static final String
JPA_ENTITY_NAME

The configuration parameter holding the JPA entity name

Method Summary

Modifier and TypeMethod and Description
public default void
configure(Type
The id property type descriptor
type
,
Properties
param values, keyed by parameter name
parameters
,
ServiceRegistry
Access to service that may be needed.
serviceRegistry
)

Implements org.hibernate.id.Configurable.configure.

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

Returns:

a new identifier
generate
(SharedSessionContractImplementor
The session from which the request originates
session
,
Object
the entity or collection (idbag) for which the id is being generated
object
)

Generate a new identifier.

public default Object
generate(SharedSessionContractImplementor
The session from which the request originates.
session
,
Object
The instance of the object owning the attribute for which we are generating a value.
owner
,
Object
The current value assigned to the property, or null
currentValue
,
EventType
The type of event that has triggered generation of a new value
eventType
)

Implements org.hibernate.generator.BeforeExecutionGenerator.generate.

Generate a value.
public default EnumSet<EventType>
getEventTypes()

Implements org.hibernate.generator.Generator.getEventTypes.

The event types for which this generator should be called to produce a new value.
public default void
initialize(SqlStringGenerationContext
A context to help generate SQL strings
context
)

Initializes this instance, in particular pre-generates SQL as necessary.

public default void
registerExportables(Database
The database instance
database
)

Implements org.hibernate.boot.model.relational.ExportableProducer.registerExportables.

Register database objects used by this identifier generator, for example, a sequence or tables.
public default boolean

Returns:

JDBC batch inserts are supported.
supportsJdbcBatchInserts
()

Deprecated since 6.2. this method is no longer called
Check if JDBC batch inserts are supported.
Inherited from org.hibernate.generator.BeforeExecutionGenerator:
generatedOnExecution

Field Detail

CONTRIBUTOR_NAMEback to summary
public static final String CONTRIBUTOR_NAME

The contributor that contributed this generator

ENTITY_NAMEback to summary
public static final String ENTITY_NAME

The configuration parameter holding the entity name

GENERATOR_NAMEback to summary
public static final String GENERATOR_NAME

The configuration parameter holding the name of this identifier generator.

See Also
org.hibernate.annotations.GenericGenerator#name(), jakarta.persistence.GeneratedValue#generator()
JPA_ENTITY_NAMEback to summary
public static final String JPA_ENTITY_NAME

The configuration parameter holding the JPA entity name

Method Detail

configureback to summary
public default void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry)

Implements 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, and before registerExportables(Database).

Parameters
type:Type

The id property type descriptor

parameters:Properties

param values, keyed by parameter name

serviceRegistry:ServiceRegistry

Access to service that may be needed.

Annotations
@Override
Exceptions
MappingException:
If configuration fails.
generateback to summary
public Object generate(SharedSessionContractImplementor session, Object object)

Generate a new identifier.

Parameters
session:SharedSessionContractImplementor

The session from which the request originates

object:Object

the entity or collection (idbag) for which the id is being generated

Returns:Object

a new identifier

Exceptions
HibernateException:
Indicates trouble generating the identifier
generateback to summary
public default Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType)

Implements org.hibernate.generator.BeforeExecutionGenerator.generate.

Generate a value.

The currentValue is usually null for id generation.

Parameters
session:SharedSessionContractImplementor

Doc from org.hibernate.generator.BeforeExecutionGenerator.generate.

The session from which the request originates.

owner:Object

Doc from org.hibernate.generator.BeforeExecutionGenerator.generate.

The instance of the object owning the attribute for which we are generating a value.

currentValue:Object

Doc from org.hibernate.generator.BeforeExecutionGenerator.generate.

The current value assigned to the property, or null

eventType:EventType

Doc from org.hibernate.generator.BeforeExecutionGenerator.generate.

The type of event that has triggered generation of a new value

Returns:Object

Doc from org.hibernate.generator.BeforeExecutionGenerator.generate.

The generated value

Annotations
@Override
getEventTypesback to summary
public default EnumSet<EventType> getEventTypes()

Implements org.hibernate.generator.Generator.getEventTypes.

Doc from org.hibernate.generator.Generator.getEventTypes.

The event types for which this generator should be called to produce a new value.

Identifier generators must return EventTypeSets#INSERT_ONLY.

Returns:EnumSet<EventType>

EventTypeSets#INSERT_ONLY

Annotations
@Override
initializeback to summary
public default void initialize(SqlStringGenerationContext context)

Initializes this instance, in particular pre-generates SQL as necessary.

This method is called after registerExportables(Database), and before first use.

Parameters
context:SqlStringGenerationContext

A context to help generate SQL strings

registerExportablesback to summary
public default void registerExportables(Database database)

Implements org.hibernate.boot.model.relational.ExportableProducer.registerExportables.

Register database objects used by this identifier generator, for example, a sequence or tables.

This method is called just once, after configure(Type, Properties, ServiceRegistry).

Parameters
database:Database

The database instance

Annotations
@Override
supportsJdbcBatchInsertsback to summary
public default boolean supportsJdbcBatchInserts()

Deprecated

since 6.2.

this method is no longer called

Check if JDBC batch inserts are supported.

Returns:boolean

JDBC batch inserts are supported.

Annotations
@Deprecated
since:6.2