Class GenericGeneratorGeneration
- All Implemented Interfaces:
Serializable, ExportableProducer, AnnotationBasedGenerator<GenericGenerator>, BeforeExecutionGenerator, Generator, OnExecutionGenerator, BulkInsertionCapableIdentifierGenerator, Configurable, IdentifierGenerator
GenericGenerator.- Since:
- 8.0
- See Also:
-
Field Summary
Fields inherited from interface IdentifierGenerator
CONTRIBUTOR_NAME, ENTITY_NAME, GENERATOR_NAME, JPA_ENTITY_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermine if this generator allows identifier values to be manually assigned to the entity instance before persisting it.booleanDetermine if this generator allows generated fields to be manually assigned a value on events which do not trigger value generation.Return the select expression fragment, if any, that generates the identifier values.generate(SharedSessionContractImplementor session, Object object) Generate a new identifier.generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType) Generate a value.booleangeneratedBeforeExecution(Object entity, SharedSessionContractImplementor session) Determines if the property value is generated before in Java code that executes before the row is written.booleanDetermines if the property value is generated when a row is written to the database, or in Java code that executes before the row is written.booleangeneratedOnExecution(Object entity, SharedSessionContractImplementor session) Determines if the property value is generated when a row is written to the database.boolean[]getColumnInclusions(Dialect dialect, EventType eventType) Indicates which columns should be included in SQL for the given event type.The event types for which this generator should be called to produce a new value.getGeneratedIdentifierDelegate(EntityPersister persister) TheInsertGeneratedIdentifierDelegateused to retrieve the generated value if this object is an identifier generator.Class<?> The Java type of the generated values.String[]getReferencedColumnValues(Dialect dialect) A SQL expression indicating how to calculate the generated values when the mapped columns are included in the SQL statement.String[]getReferencedColumnValues(Dialect dialect, EventType eventType) A SQL expression indicating how to calculate the generated values when the mapped columns are included in the SQL statement for the given event type.String[]getUniqueKeyPropertyNames(EntityPersister persister) The name of a property of the entity which may be used to locate the just-inserted row containing the generated value.voidinitialize(GenericGenerator annotation, GeneratorCreationContext context) Initializes this generation strategy for the given annotation instance.booleanreferenceColumnsInSql(Dialect dialect) Determines if the columns whose values are generated are included in the column list of the SQLinsertorupdatestatement.booleanreferenceColumnsInSql(Dialect dialect, EventType eventType) Determines if the columns whose values are generated are included in the column list of the SQLinsertorupdatestatement for the given event type.booleanDoes this generator require an identity (autoincrement) column.booleanGiven the configuration of this generator, is identifier generation as part of bulk insertion supported?booleanDetermines if the property values are written to JDBC as the argument of a JDBC?parameter.booleanwritePropertyValue(EventType eventType) Determines if the property values are written to JDBC as the argument of a JDBC?parameter for the given event type.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AnnotationBasedGenerator
initializeMethods inherited from interface Configurable
configure, initializeMethods inherited from interface Generator
generatesOnForceIncrement, generatesOnInsert, generatesOnUpdate, generatesSometimesMethods inherited from interface IdentifierGenerator
configure, registerExportables
-
Constructor Details
-
GenericGeneratorGeneration
public GenericGeneratorGeneration()
-
-
Method Details
-
getDelegate
-
initialize
Description copied from interface:AnnotationBasedGeneratorInitializes this generation strategy for the given annotation instance.- Specified by:
initializein interfaceAnnotationBasedGenerator<GenericGenerator>- Parameters:
annotation- an instance of the strategy's annotation type. Typically, implementations will retrieve the annotation's attribute values and store them in fields.context- aGeneratorCreationContext
-
generatedOnExecution
public boolean generatedOnExecution()Description copied from interface:GeneratorDetermines if the property value is generated when a row is written to the database, or in Java code that executes before the row is written.- Generators which only implement
BeforeExecutionGeneratormust resultfalse. - Generators which only implement
OnExecutionGeneratormust resulttrue. - Generators which implement both subinterfaces may decide at runtime what value to return.
- Specified by:
generatedOnExecutionin interfaceBeforeExecutionGenerator- Specified by:
generatedOnExecutionin interfaceGenerator- Specified by:
generatedOnExecutionin interfaceOnExecutionGenerator- Returns:
trueif the value is generated by the database as a side effect of the execution of aninsertorupdatestatement, or false if it is generated in Java code before the statement is executed via JDBC.
- Generators which only implement
-
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- Specified by:
getEventTypesin interfaceIdentifierGenerator- Returns:
EventTypeSets.INSERT_ONLY
-
getGeneratedType
Description copied from interface:GeneratorThe Java type of the generated values.- Specified by:
getGeneratedTypein interfaceGenerator- Returns:
- the generated type, or
nullif the type is not known
-
allowAssignedIdentifiers
public boolean allowAssignedIdentifiers()Description copied from interface:GeneratorDetermine if this generator allows identifier values to be manually assigned to the entity instance before persisting it. This is useful when, for example, needing existing assigned values to be used as identifiers and falling back to generated values by default.- Specified by:
allowAssignedIdentifiersin interfaceGenerator- Returns:
trueif this generator allows pre-assigned identifier values,falseotherwise (default).
-
allowMutation
public boolean allowMutation()Description copied from interface:GeneratorDetermine if this generator allows generated fields to be manually assigned a value on events which do not trigger value generation.- Specified by:
allowMutationin interfaceGenerator- Returns:
trueif this generator allows manually assigned values,falseotherwise (default).
-
requiresIdentityColumn
public boolean requiresIdentityColumn()Description copied from interface:GeneratorDoes this generator require an identity (autoincrement) column.- Specified by:
requiresIdentityColumnin interfaceGenerator
-
referenceColumnsInSql
Description copied from interface:OnExecutionGeneratorDetermines if the columns whose values are generated are included in the column list of the SQLinsertorupdatestatement. For example, this method should return:trueif the value is generated by calling a SQL function likecurrent_timestamp, orfalseif the value is generated by a trigger, bygenerated always as, or using a column default value.
- Specified by:
referenceColumnsInSqlin interfaceOnExecutionGenerator- Returns:
trueif the column is included in the column list of the SQL statement.
-
referenceColumnsInSql
Description copied from interface:OnExecutionGeneratorDetermines if the columns whose values are generated are included in the column list of the SQLinsertorupdatestatement for the given event type.The default implementation delegates to
OnExecutionGenerator.referenceColumnsInSql(Dialect).- Specified by:
referenceColumnsInSqlin interfaceOnExecutionGenerator
-
writePropertyValue
public boolean writePropertyValue()Description copied from interface:OnExecutionGeneratorDetermines if the property values are written to JDBC as the argument of a JDBC?parameter.- Specified by:
writePropertyValuein interfaceOnExecutionGenerator
-
writePropertyValue
Description copied from interface:OnExecutionGeneratorDetermines if the property values are written to JDBC as the argument of a JDBC?parameter for the given event type.The default implementation delegates to
OnExecutionGenerator.writePropertyValue().- Specified by:
writePropertyValuein interfaceOnExecutionGenerator
-
getReferencedColumnValues
Description copied from interface:OnExecutionGeneratorA 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_timestampornextval('mysequence'), or - syntactic markers like
default.
- Specified by:
getReferencedColumnValuesin interfaceOnExecutionGenerator- Parameters:
dialect- The SQL dialect, allowing generation of an expression in dialect-specific SQL.- Returns:
- The column value to be used in the generated SQL statement.
- function calls like
-
getReferencedColumnValues
Description copied from interface:OnExecutionGeneratorA SQL expression indicating how to calculate the generated values when the mapped columns are included in the SQL statement for the given event type.The default implementation delegates to
OnExecutionGenerator.getReferencedColumnValues(Dialect).- Specified by:
getReferencedColumnValuesin interfaceOnExecutionGenerator
-
getColumnInclusions
Description copied from interface:OnExecutionGeneratorIndicates which columns should be included in SQL for the given event type. Anullreturn value indicates that all columns are included.- Specified by:
getColumnInclusionsin interfaceOnExecutionGenerator
-
getGeneratedIdentifierDelegate
Description copied from interface:OnExecutionGeneratorTheInsertGeneratedIdentifierDelegateused to retrieve the generated value if this object is an identifier generator.This is ignored by
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:
- a database which supports some form of
insert ... returningsyntax, or can do the same thing using the JDBCgetGeneratedKeys()API, or - a second unique key of the entity, that is, a property annotated
@NaturalId.
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:
IdentityGenerator. And the need for customized behavior for identity columns is the reason why this layer-breaking method exists.- Specified by:
getGeneratedIdentifierDelegatein interfaceOnExecutionGenerator
- a database which supports some form of
-
getUniqueKeyPropertyNames
Description copied from interface:OnExecutionGeneratorThe name of a property of the entity which may be used to locate the just-inserted row containing the generated value. Of course, the columns mapped by this property should form a unique key of the entity.The default implementation uses the
@NaturalIdproperty, if there is one.- Specified by:
getUniqueKeyPropertyNamesin interfaceOnExecutionGenerator
-
supportsBulkInsertionIdentifierGeneration
public boolean supportsBulkInsertionIdentifierGeneration()Description copied from interface:BulkInsertionCapableIdentifierGeneratorGiven the configuration of this generator, is identifier generation as part of bulk insertion supported?- Specified by:
supportsBulkInsertionIdentifierGenerationin interfaceBulkInsertionCapableIdentifierGenerator- Returns:
trueif bulk insertions are supported;falseotherwise.
-
determineBulkInsertionIdentifierGenerationSelectFragment
public String determineBulkInsertionIdentifierGenerationSelectFragment(SqlStringGenerationContext context) Description copied from interface:BulkInsertionCapableIdentifierGeneratorReturn the select expression fragment, if any, that generates the identifier values.- Specified by:
determineBulkInsertionIdentifierGenerationSelectFragmentin interfaceBulkInsertionCapableIdentifierGenerator- Returns:
- The identifier value generation fragment (SQL).
nullindicates that no fragment is needed.
-