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.
BeforeExecutionGenerator#generate(SharedSessionContractImplementor, Object, Object, EventType).
In this case, the generated value is written to the database just like any other field
or property value. The Java code may, of course, ask the database to actually generate
the value. Examples include timestamp generation using the JVM system time, and id
generation using a database sequence.
default column value specified in DDL, for example, or it might be generated
by a SQL expression occurring explicitly in the SQL insert or update
statement. In this case, the generated value may be retrieved from the database using a
SQL select, though in certain cases this additional round trip may be avoided.
An important example is id generation using an identity column.
generatedOnExecution.
Generically, a generator may be integrated with the program using the meta-annotation
org., 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:
AnnotationBasedGenerator, and receive the annotation as an argument to
AnnotationBasedGenerator#initialize,
AnnotationBasedGenerator#initialize,
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:
getEventTypes() must return EventTypeSets#INSERT_ONLY. It may be integrated
using the org.hibernate.annotations.IdGeneratorType meta-annotation or the older-style
org.hibernate.annotations.GenericGenerator annotation.
getEventTypes() must return EventTypeSets#INSERT_AND_UPDATE.
It may be integrated using org.hibernate.annotations.ValueGenerationType meta-annotation.
org.hibernate.annotations.ValueGenerationType , org.hibernate.annotations.IdGeneratorType , org.hibernate.annotations.Generated
| Modifier and Type | Method 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.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.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 | Returns: a set ofEventTypes.The event types for which this generator should be called to produce a new value. |
| generatedOnExecution | back 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.
| |
| generatedOnExecution | back 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
| |
| generatesOnInsert | back to summary |
|---|---|
| public default boolean generatesOnInsert() | |
| generatesOnUpdate | back to summary |
|---|---|
| public default boolean generatesOnUpdate() | |
| generatesSometimes | back to summary |
|---|---|
| public default boolean generatesSometimes() | |
| getEventTypes | back to summary |
|---|---|
| public EnumSet The event types for which this generator should be called to produce a new value.
Identifier generators must return | |