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. AnyBeforeExecutionGeneratorwith timingEventTypeSets.INSERT_ONLYmay now be used.This interface extends
BeforeExecutionGeneratorwith 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,PersistentIdentifierGeneratorextendsExportableProducer, 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
IdentifierGeneratorare usually created and configured by theIdentifierGeneratorFactoryservice. It's not usually correct to use anIdentifierGeneratorwith theIdGeneratorTypemeta-annotation.
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONTRIBUTOR_NAMEThe contributor that contributed this generatorstatic StringENTITY_NAMEThe configuration parameter holding the entity namestatic StringGENERATOR_NAMEThe configuration parameter holding the name of this identifier generator.static StringJPA_ENTITY_NAMEThe 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 voidconfigure(Type type, Properties parameters, ServiceRegistry serviceRegistry)Configure this instance, given the value of parameters specified by the user as<param>elements.Objectgenerate(SharedSessionContractImplementor session, Object object)Generate a new identifier.default Objectgenerate(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 voidregisterExportables(Database database)Register database objects used by this identifier generator, for example, a sequence or tables.default booleansupportsJdbcBatchInserts()Deprecated.this method is no longer called-
Methods inherited from interface org.hibernate.generator.BeforeExecutionGenerator
generatedOnExecution
-
Methods inherited from interface org.hibernate.id.Configurable
create, initialize
-
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:
configurein 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:
registerExportablesin interfaceExportableProducer- Parameters:
database- The database instance
-
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
currentValueis usually null for id generation.- Specified by:
generatein 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, ornulleventType- 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:GeneratorThe event types for which this generator should be called to produce a new value.Identifier generators must return
EventTypeSets.INSERT_ONLY.- Specified by:
getEventTypesin 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.
-
-