Annotation Type Generated


  • @Target({FIELD,METHOD})
    @Retention(RUNTIME)
    public @interface Generated
    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 call Session.refresh(Object) explicitly to synchronize state held in memory with state generated by the database when a SQL INSERT or UPDATE is executed.

    This is most useful for working with database tables where a column value is populated by a database trigger. A second possible scenario is the use of Generated(INSERT) with ColumnDefault.

    • For identity/autoincrement columns mapped to an identifier property, use GeneratedValue.
    • For columns with a generated always as clause, prefer the GeneratedColumn annotation.
    See Also:
    GeneratedValue, ColumnDefault, GeneratedColumn
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      GenerationTime value
      Specifies the events that cause the value to be generated by the database.
    • Element Detail

      • value

        GenerationTime value
        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.ALWAYS, the generated value will be selected after each SQL INSERT or UPDATE statement is executed.