Top Description Methods
org.hibernate.annotations

public @Interface Generated

extends Annotation
Annotations
@ValueGenerationType
generatedBy:GeneratedGeneration
@IdGeneratorType:GeneratedGeneration
@Target:FIELD, METHOD
@Retention:RUNTIME
Imports
java.lang.annotation.Retention, .Target, org.hibernate.generator.EventType, org.hibernate.generator.internal.GeneratedGeneration

Specifies that the value of the annotated property is generated by the database. The generated value will be automatically retrieved using a SQL select after it is generated.

@Generated relieves the program of the need to explicitly call refresh() to synchronize state held in memory with state generated by the database when a SQL insert or update is executed.

This is most useful when:

On the other hand:

Author
Emmanuel Bernard
See Also
jakarta.persistence.GeneratedValue, ColumnDefault, GeneratedColumn

Method Summary

Modifier and TypeMethod and Description
public EventType[]
event()

Specifies the events that cause the value to be generated by the database.

public String
sql()

A SQL expression used to generate the value of the column mapped by the annotated property.

public GenerationTime
value()

Deprecated since 6.2. use event()
Specifies the events that cause the value to be generated by the database.
public boolean

Returns:

true if the current value should be included in SQL insert and update statements.
writable
()

Determines if the value currently assigned to the annotated property is included in SQL insert and update statements.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

eventback to summary
public EventType[] event()

Specifies the events that cause the value to be generated by the database.

  • If EventType#INSERT is included, the generated value will be selected after each SQL insert statement is executed.
  • If EventType#UPDATE is included, the generated value will be selected after each SQL update statement is executed.
sqlback to summary
public String sql()

A SQL expression used to generate the value of the column mapped by the annotated property. The expression is included in generated SQL insert and update statements.

valueback to summary
public GenerationTime value()

Deprecated

since 6.2.

use event()

Specifies the events that cause the value to be generated by the database.

  • If GenerationTime#INSERT, the generated value will be selected after each SQL insert statement is executed.
  • If GenerationTime#UPDATE, the generated value will be selected after each SQL update statement is executed.
  • If GenerationTime#ALWAYS, the generated value will be selected after each SQL insert or update statement is executed.
Annotations
@Deprecated
since:6.2
writableback to summary
public boolean writable()

Determines if the value currently assigned to the annotated property is included in SQL insert and update statements. This is useful if the generated value is obtained by transforming the assigned property value as it is being written.

Often used in combination with SQLInsert, SQLUpdate, or ColumnTransformer#write().

Returns:boolean

true if the current value should be included in SQL insert and update statements.