Package org.hibernate.generator
Interface BeforeExecutionGenerator
-
- All Superinterfaces:
Generator,Serializable
- All Known Subinterfaces:
AnnotationValueGeneration<A>,IdentifierGenerator,OptimizableGenerator,PersistentIdentifierGenerator,ValueGeneration
- All Known Implementing Classes:
AbstractUUIDGenerator,Assigned,CompositeNestedGeneratedValueGenerator,CreationTimestampGeneration,CurrentTimestampGeneration,ForeignGenerator,GUIDGenerator,IncrementGenerator,OrderedSequenceGenerator,SequenceStyleGenerator,SourceGeneration,TableGenerator,TenantIdGeneration,UpdateTimestampGeneration,UuidGenerator,UUIDGenerator,UUIDHexGenerator,VersionGeneration,VmValueGeneration
public interface BeforeExecutionGenerator extends Generator
A generator that is called to produce a value just before a row is written to the database. Thegenerate(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object, java.lang.Object, org.hibernate.generator.EventType)method may execute arbitrary Java code. It may even, in principle, access the database via JDBC. But however it's produced, the generated value is sent to the database via a parameter of a JDBC prepared statement, just like any other field or property value.Any
BeforeExecutionGeneratorwith generation event typesEventTypeSets.INSERT_ONLYmay be used to produce identifiers. The built-in identifier generators all implement the older extension pointIdentifierGenerator, which is a subtype of this interface, but that is no longer a requirement for custom id generators.A custom id generator may be integrated with the program using either:
- the meta-annotation
IdGeneratorTypeor - the annotation
GenericGenerator.
On the other hand, generators for regular fields and properties may be integrated using
ValueGenerationType, as for anyGenerator.- Since:
- 6.2
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Objectgenerate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType)Generate a value.default booleangeneratedOnExecution()Determines 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.-
Methods inherited from interface org.hibernate.generator.Generator
generatesOnInsert, generatesOnUpdate, generatesSometimes, getEventTypes
-
-
-
-
Method Detail
-
generate
Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType)
Generate a value.- 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
-
generatedOnExecution
default 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 interfaceGenerator- 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
-
-