Interface IdentifierGenerator
-
- All Superinterfaces:
BeforeExecutionGenerator
,Configurable
,ExportableProducer
,Generator
,Serializable
- All Known Subinterfaces:
OptimizableGenerator
,PersistentIdentifierGenerator
- All Known Implementing Classes:
AbstractUUIDGenerator
,Assigned
,CompositeNestedGeneratedValueGenerator
,ForeignGenerator
,GUIDGenerator
,IncrementGenerator
,OrderedSequenceGenerator
,SequenceStyleGenerator
,TableGenerator
,UUIDGenerator
,UUIDHexGenerator
public interface IdentifierGenerator extends BeforeExecutionGenerator, ExportableProducer, Configurable
A classic extension point from the very earliest days of Hibernate, this interface is no longer the only way to generate identifiers. AnyBeforeExecutionGenerator
with timingEventTypeSets.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 implementExportableProducer
. For the sake of convenience,PersistentIdentifierGenerator
extendsExportableProducer
, 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:- several "standard" parameters with keys defined as static members of this interface: "entity_name", "jpa_entity_name", "GENERATOR_NAME", "CONTRIBUTOR", along with
- additional hardcoded parameters supplied by Hibernate to its built-in generators, depending on the generator class, and, possibly,
- parameters specified
using
GenericGenerator.parameters()
.
Instances of
IdentifierGenerator
are usually created and configured by theIdentifierGeneratorFactory
service. It's not usually correct to use anIdentifierGenerator
with theIdGeneratorType
meta-annotation.
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONTRIBUTOR_NAME
The contributor that contributed this generatorstatic String
ENTITY_NAME
The configuration parameter holding the entity namestatic String
GENERATOR_NAME
The configuration parameter holding the name of this identifier generator.static String
JPA_ENTITY_NAME
The configuration parameter holding the JPA entity name
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default void
configure(Type type, Properties parameters, ServiceRegistry serviceRegistry)
Configure this instance, given the value of parameters specified by the user as<param>
elements.Object
generate(SharedSessionContractImplementor session, Object object)
Generate a new identifier.default Object
generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType)
Generate a value.default EnumSet<EventType>
getEventTypes()
The event types for which this generator should be called to produce a new value.default void
initialize(SqlStringGenerationContext context)
Initializes this instance, in particular pre-generates SQL as necessary.default void
registerExportables(Database database)
Register database objects used by this identifier generator, for example, a sequence or tables.default boolean
supportsJdbcBatchInserts()
Deprecated.this method is no longer called-
Methods inherited from interface org.hibernate.generator.BeforeExecutionGenerator
generatedOnExecution
-
Methods inherited from interface org.hibernate.generator.Generator
allowAssignedIdentifiers, generatedOnExecution, generatesOnInsert, generatesOnUpdate, generatesSometimes
-
-
-
-
Field Detail
-
ENTITY_NAME
static final String ENTITY_NAME
The configuration parameter holding the entity name- See Also:
- Constant Field Values
-
JPA_ENTITY_NAME
static final String JPA_ENTITY_NAME
The configuration parameter holding the JPA entity name- See Also:
- Constant Field Values
-
GENERATOR_NAME
static final String GENERATOR_NAME
The configuration parameter holding the name of this identifier generator.
-
CONTRIBUTOR_NAME
static final String CONTRIBUTOR_NAME
The contributor that contributed this generator- See Also:
- Constant Field Values
-
-
Method Detail
-
configure
default void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry)
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)
.- Specified by:
configure
in interfaceConfigurable
- Parameters:
type
- The id property type descriptorparameters
- param values, keyed by parameter nameserviceRegistry
- Access to service that may be needed.- Throws:
MappingException
- If configuration fails.
-
registerExportables
default void registerExportables(Database database)
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)
.- Specified by:
registerExportables
in interfaceExportableProducer
- Parameters:
database
- The database instance
-
initialize
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
- A context to help generate SQL strings
-
generate
Object generate(SharedSessionContractImplementor session, Object object)
Generate a new identifier.- Parameters:
session
- The session from which the request originatesobject
- the entity or collection (idbag) for which the id is being generated- Returns:
- a new identifier
- Throws:
HibernateException
- Indicates trouble generating the identifier
-
generate
default Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType)
Generate a value.The
currentValue
is usually null for id generation.- Specified by:
generate
in interfaceBeforeExecutionGenerator
- Parameters:
session
- The session from which the request originates.owner
- The instance of the object owning the attribute for which we are generating a value.currentValue
- The current value assigned to the property, ornull
eventType
- The type of event that has triggered generation of a new value- Returns:
- The generated value
-
getEventTypes
default EnumSet<EventType> getEventTypes()
Description copied from interface:Generator
The event types for which this generator should be called to produce a new value.Identifier generators must return
EventTypeSets.INSERT_ONLY
.- Specified by:
getEventTypes
in interfaceGenerator
- Returns:
EventTypeSets.INSERT_ONLY
-
supportsJdbcBatchInserts
@Deprecated(since="6.2") default boolean supportsJdbcBatchInserts()
Deprecated.this method is no longer calledCheck if JDBC batch inserts are supported.- Returns:
- JDBC batch inserts are supported.
-
-