Class Assigned

java.lang.Object
org.hibernate.generator.Assigned
All Implemented Interfaces:
Serializable, Generator
Direct Known Subclasses:
Assigned

@Internal public class Assigned extends Object implements Generator
A Generator that doesn't generate.

Identifier fields with an Assigned generator must be assigned a value by the application program.

This replaces the Assigned identifier generation strategy from older versions of Hibernate.

Since:
7.0
See Also:
  • Constructor Details

    • Assigned

      public Assigned()
  • Method Details

    • generatedOnExecution

      public boolean generatedOnExecution()
      Description copied from interface: Generator
      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.
      Specified by:
      generatedOnExecution in interface Generator
      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

      public boolean generatedOnExecution(Object entity, SharedSessionContractImplementor session)
      Description copied from interface: Generator
      Determines if the property value is generated when a row is written to the database.

      Defaults to Generator.generatedOnExecution(), but may be overridden to allow conditional on-execution value generation based on the current state of the owner entity.

      Specified by:
      generatedOnExecution in interface Generator
      Parameters:
      entity - The instance of the entity owning the attribute for which we are generating a value.
      session - The session from which the request originates.
      Returns:
      true if the value is generated by the database as a side effect of the execution of an insert or update statement.
      See Also:
    • generatedBeforeExecution

      public boolean generatedBeforeExecution(Object entity, SharedSessionContractImplementor session)
      Description copied from interface: Generator
      Determines if the property value is generated before in Java code that executes before the row is written.

      Defaults to !generatedOnExecution(), but may be overridden to allow conditional before-execution value generation based on the current state of the owner entity.

      Specified by:
      generatedBeforeExecution in interface Generator
      Parameters:
      entity - The instance of the entity owning the attribute for which we are generating a value.
      session - The session from which the request originates.
      Returns:
      true if the value is generated in Java code before the statement is executed via JDBC.
      See Also:
    • allowAssignedIdentifiers

      public boolean allowAssignedIdentifiers()
      Description copied from interface: Generator
      Determine if this generator allows identifier values to be manually assigned to the entity instance before persisting it. This is useful when, for example, needing existing assigned values to be used as identifiers and falling back to generated values by default.
      Specified by:
      allowAssignedIdentifiers in interface Generator
      Returns:
      true if this generator allows pre-assigned identifier values, false otherwise (default).
    • allowMutation

      public boolean allowMutation()
      Description copied from interface: Generator
      Determine if this generator allows generated fields to be manually assigned a value on events which do not trigger value generation.
      Specified by:
      allowMutation in interface Generator
      Returns:
      true if this generator allows manually assigned values, false otherwise (default).
    • getEventTypes

      public EnumSet<EventType> getEventTypes()
      Description copied from interface: Generator
      The event types for which this generator should be called to produce a new value.

      Identifier generators must return EventTypeSets.INSERT_ONLY.

      Specified by:
      getEventTypes in interface Generator
      Returns:
      a set of EventTypes.
    • generatesSometimes

      public boolean generatesSometimes()
      Specified by:
      generatesSometimes in interface Generator
    • generatesOnInsert

      public boolean generatesOnInsert()
      Specified by:
      generatesOnInsert in interface Generator
    • generatesOnUpdate

      public boolean generatesOnUpdate()
      Specified by:
      generatesOnUpdate in interface Generator