Top Description Methods
org.hibernate.generator

public Interface BeforeExecutionGenerator

extends Generator
Known Direct Subinterfaces
org.hibernate.id.IdentifierGenerator, org.hibernate.tuple.ValueGeneration
Known Direct Implementers
org.hibernate.generator.internal.CurrentTimestampGeneration, org.hibernate.generator.internal.SourceGeneration, org.hibernate.generator.internal.TenantIdGeneration, org.hibernate.generator.internal.VersionGeneration, org.hibernate.id.uuid.UuidGenerator, org.hibernate.tuple.VmValueGeneration
Imports
org.hibernate.engine.spi.SharedSessionContractImplementor

A generator that is called to produce a value just before a row is written to the database. The generate 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 BeforeExecutionGenerator with generation event types EventTypeSets#INSERT_ONLY may be used to produce identifiers. The built-in identifier generators all implement the older extension point org.hibernate.id.IdentifierGenerator, 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:

On the other hand, generators for regular fields and properties may be integrated using org.hibernate.annotations.ValueGenerationType, as for any Generator.

Authors
Steve Ebersole, Gavin King
Since
6.2

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

The generated value
generate
(SharedSessionContractImplementor
The session from which the request originates.
session
,
Object
The instance of the object owning the attribute for which we are generating a value.
owner
,
Object
The current value assigned to the property, or null
currentValue
,
EventType
The type of event that has triggered generation of a new value
eventType
)

Generate a value.

public default boolean
generatedOnExecution()

Implements org.hibernate.generator.Generator.generatedOnExecution.

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.
Inherited from org.hibernate.generator.Generator:
generatedOnExecutiongeneratesOnInsertgeneratesOnUpdategeneratesSometimesgetEventTypes

Method Detail

generateback to summary
public Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType)

Generate a value.

Parameters
session:SharedSessionContractImplementor

The session from which the request originates.

owner:Object

The instance of the object owning the attribute for which we are generating a value.

currentValue:Object

The current value assigned to the property, or null

eventType:EventType

The type of event that has triggered generation of a new value

Returns:Object

The generated value

generatedOnExecutionback to summary
public default boolean generatedOnExecution()

Implements org.hibernate.generator.Generator.generatedOnExecution.

Doc from org.hibernate.generator.Generator.generatedOnExecution.

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.

  • Generators which only implement BeforeExecutionGenerator must result false.
  • Generators which only implement OnExecutionGenerator must result true.
  • Generators which implement both subinterfaces may decide at runtime what value to return.
Returns:boolean

true if the value is generated by the database as a side effect of the execution of an insert or update statement, or false if it is generated in Java code before the statement is executed via JDBC.

Annotations
@Override