Class CompositeNestedGeneratedValueGenerator
- All Implemented Interfaces:
Serializable, ExportableProducer, BeforeExecutionGenerator, Generator, OnExecutionGenerator, Configurable, IdentifierGenerator, IdentifierGeneratorAggregator
This generator is used implicitly for all composite identifier scenarios if an explicit generator is not in place. So it make sense to discuss the various potential scenarios:
-
"embedded" composite identifier - this is possible only in HBM mappings
as
<composite-id/>(notice the lack of both a name and class attribute declarations). The term"embedded"here refers to the Hibernate usage which is actually the exact opposite of the JPA meaning of "embedded". Essentially this means that the entity class itself holds the named composite pk properties. This is very similar to the JPA@IdClassusage, though without a separate pk-class for loading. -
pk-class as entity attribute - this is possible in both annotations (
@EmbeddedId) and HBM mappings (<composite-id name="idAttributeName" class="PkClassName"/>) -
"embedded" composite identifier with a pk-class - this is the JPA
@IdClassuse case and is only possible in annotations
Most of the grunt work is done in Component.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceContract for declaring how to locate the context for sub-value injection.static interfaceContract for performing the actual sub-value generation, usually injecting it into the determined context -
Field Summary
Fields inherited from interface IdentifierGenerator
CONTRIBUTOR_NAME, ENTITY_NAME, GENERATOR_NAME, JPA_ENTITY_NAME -
Constructor Summary
ConstructorsConstructorDescriptionCompositeNestedGeneratedValueGenerator(CompositeNestedGeneratedValueGenerator.GenerationContextLocator generationContextLocator, ComponentType componentType) CompositeNestedGeneratedValueGenerator(CompositeNestedGeneratedValueGenerator.GenerationContextLocator generationContextLocator, ComponentType componentType, List<Generator> generators, String[] columnValues, boolean[] columnInclusions, boolean[] generatedOnExecutionColumns) CompositeNestedGeneratedValueGenerator(CompositeNestedGeneratedValueGenerator original, List<CompositeNestedGeneratedValueGenerator.GenerationPlan> generationPlans) -
Method Summary
Modifier and TypeMethodDescriptionvoidgenerate(SharedSessionContractImplementor session, Object object) Generate a new identifier.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.getGeneratedIdentifierDelegate(EntityPersister persister) TheInsertGeneratedIdentifierDelegateused to retrieve the generated value if this object is an identifier generator.boolean[]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.booleanvoidinitialize(SqlStringGenerationContext context) Initializes this instance, pre-generating SQL if necessary.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.voidregisterExportables(Database database) Register database objects used by this identifier generator, for example, a sequence or tables.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 Configurable
configureMethods inherited from interface Generator
allowAssignedIdentifiers, allowMutation, generatesOnForceIncrement, generatesOnInsert, generatesOnUpdate, generatesSometimesMethods inherited from interface IdentifierGenerator
configure, generate, getEventTypesMethods inherited from interface OnExecutionGenerator
getUniqueKeyPropertyNames
-
Constructor Details
-
CompositeNestedGeneratedValueGenerator
public CompositeNestedGeneratedValueGenerator(CompositeNestedGeneratedValueGenerator.GenerationContextLocator generationContextLocator, ComponentType componentType) -
CompositeNestedGeneratedValueGenerator
public CompositeNestedGeneratedValueGenerator(CompositeNestedGeneratedValueGenerator original, List<CompositeNestedGeneratedValueGenerator.GenerationPlan> generationPlans) -
CompositeNestedGeneratedValueGenerator
public CompositeNestedGeneratedValueGenerator(CompositeNestedGeneratedValueGenerator.GenerationContextLocator generationContextLocator, ComponentType componentType, List<Generator> generators, String[] columnValues, boolean[] columnInclusions, boolean[] generatedOnExecutionColumns)
-
-
Method Details
-
addGeneratedValuePlan
-
hasAssignedValues
public boolean hasAssignedValues() -
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
-
registerExportables
Description copied from interface:IdentifierGeneratorRegister database objects used by this identifier generator, for example, a sequence or tables.This method is called just once, after
Configurable.configure(GeneratorCreationContext, Properties).- Specified by:
registerExportablesin interfaceExportableProducer- Specified by:
registerExportablesin interfaceIdentifierGenerator- Parameters:
database- The database instance
-
initialize
Description copied from interface:ConfigurableInitializes this instance, pre-generating SQL if necessary.If this instance also implements
ExportableProducer, then this method is always called afterExportableProducer.registerExportables(Database), and before first use.- Specified by:
initializein interfaceConfigurable- Parameters:
context- A context to help generate SQL strings
-
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
-
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
-
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
-
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
-
getGenerationPlans
-
getGenerationContextLocator
public CompositeNestedGeneratedValueGenerator.GenerationContextLocator getGenerationContextLocator() -
getComponentType
-
getGeneratedOnExecutionColumnInclusions
public boolean[] getGeneratedOnExecutionColumnInclusions()
-