Class IdentityGenerator

    • Constructor Detail

      • IdentityGenerator

        public IdentityGenerator()
    • Method Detail

      • referenceColumnsInSql

        public boolean referenceColumnsInSql​(Dialect dialect)
        Description copied from interface: OnExecutionGenerator
        Determines if the columns whose values are generated are included in the column list of the SQL insert or update statement. For example, this method should return:
        Specified by:
        referenceColumnsInSql in interface OnExecutionGenerator
        true if the column is included in the column list of the SQL statement.
      • getReferencedColumnValues

        public String[] getReferencedColumnValues​(Dialect dialect)
        Description copied from interface: OnExecutionGenerator
        A SQL expression indicating how to calculate the generated values when the mapped columns are included in the SQL statement. The SQL expressions might be:
        • function calls like current_timestamp or nextval('mysequence'), or
        • syntactic markers like default.
        Specified by:
        getReferencedColumnValues in interface OnExecutionGenerator
        dialect - The SQL dialect, allowing generation of an expression in dialect-specific SQL.
        The column value to be used in the generated SQL statement.
      • getGeneratedIdentifierDelegate

        public InsertGeneratedIdentifierDelegate getGeneratedIdentifierDelegate​(PostInsertIdentityPersister persister)
        Description copied from interface: OnExecutionGenerator
        The InsertGeneratedIdentifierDelegate used to retrieve the generated value if this object is an identifier generator.

        This is ignored by GeneratedValuesProcessor, which handles multiple generators at once. So if this object is not an identifier generator, this method is never called.

        Note that this method arguably breaks the separation of concerns between the generator and coordinating code, by specifying how the generated value should be retrieved.

        The problem solved here is: we want to obtain an insert-generated primary key. But, sadly, without already knowing the primary key, there's no completely-generic way to locate the just-inserted row to obtain it.

        We need one of the following things:

        Alternatively, if the generated id is an identity/"autoincrement" column, we can take advantage of special platform-specific functionality to retrieve it. Taking advantage of the specialness of identity columns is the job of one particular implementation: IdentityGenerator. And the need for customized behavior for identity columns is the reason why this layer-breaking method exists.
        Specified by:
        getGeneratedIdentifierDelegate in interface OnExecutionGenerator