Top Description Methods
org.hibernate.generator

public Interface Generator

extends Serializable
Known Direct Subinterfaces
org.hibernate.generator.OnExecutionGenerator, org.hibernate.id.BulkInsertionCapableIdentifierGenerator, org.hibernate.generator.AnnotationBasedGenerator, org.hibernate.generator.BeforeExecutionGenerator
Imports
org.hibernate.engine.spi.SharedSessionContractImplementor, java.io.Serializable, java.util.EnumSet

Describes the generation of values of a certain field or property of an entity. A generated value might be generated in Java, or by the database. Every instance of this interface must implement either or both of BeforeExecutionGenerator and OnExecutionGenerator depending on whether values are generated in Java code before execution of a SQL statement, or by the database when the SQL statement is executed. A Generator may implement both interfaces and determine the timing of ID generation at runtime. Furthermore, this condition can be based on the state of the owner entity, see generatedOnExecution.

Generically, a generator may be integrated with the program using the meta-annotation org.hibernate.annotations.ValueGenerationType, which associates the generator with a Java annotation type, called the generator annotation. A generator may receive parameters from its generator annotation. The generator may either:

A generator must implement getEventTypes() to specify the events for which it should be called to produce a new value. EventTypeSets provides a convenient list of possibilities.

There are two especially important applications of this machinery:

Authors
Steve Ebersole, Gavin King
Since
6.2
See Also
org.hibernate.annotations.ValueGenerationType, org.hibernate.annotations.IdGeneratorType, org.hibernate.annotations.Generated

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

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.
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.

public default boolean

Returns:

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.
generatedOnExecution
(Object
The instance of the entity owning the attribute for which we are generating a value.
entity
,
SharedSessionContractImplementor
The session from which the request originates.
session
)

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.

public default boolean
public default boolean
public default boolean
public EnumSet<EventType>

Returns:

a set of EventTypes.
getEventTypes
()

The event types for which this generator should be called to produce a new value.

Method Detail

generatedOnExecutionback to summary
public boolean 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.

generatedOnExecutionback to summary
public default boolean generatedOnExecution(Object entity, SharedSessionContractImplementor session)

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.

Defaults to generatedOnExecution(), but can be overloaded allowing conditional value generation timing (on/before execution) based on the current state of the owner entity. Note that a generator must implement both BeforeExecutionGenerator and OnExecutionGenerator to achieve this behavior.

Parameters
entity:Object

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

session:SharedSessionContractImplementor

The session from which the request originates.

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.

Since
6.4
See Also
generatedOnExecution(), BeforeExecutionGenerator, OnExecutionGenerator
generatesOnInsertback to summary
public default boolean generatesOnInsert()
generatesOnUpdateback to summary
public default boolean generatesOnUpdate()
generatesSometimesback to summary
public default boolean generatesSometimes()
getEventTypesback to summary
public EnumSet<EventType> getEventTypes()

The event types for which this generator should be called to produce a new value.

Identifier generators must return EventTypeSets#INSERT_ONLY.

Returns:EnumSet<EventType>

a set of EventTypes.