Interface IdentifierGenerator

All Superinterfaces:
BeforeExecutionGenerator, Configurable, ExportableProducer, Generator, Serializable
All Known Subinterfaces:
OptimizableGenerator, PersistentIdentifierGenerator
All Known Implementing Classes:
AbstractUUIDGenerator, Assigned, CompositeNestedGeneratedValueGenerator, ForeignGenerator, GUIDGenerator, IncrementGenerator, OrderedSequenceGenerator, SequenceStyleGenerator, TableGenerator, UUIDGenerator, UUIDHexGenerator

public interface IdentifierGenerator extends BeforeExecutionGenerator, ExportableProducer, Configurable
A classic extension point from the very earliest days of Hibernate, this interface is no longer the only way to generate identifiers. Any BeforeExecutionGenerator with timing EventTypeSets.INSERT_ONLY may now be used.

This interface extends BeforeExecutionGenerator with some additional machinery for configuration, and for caching generated SQL.

Any identifier generator, including a generator which directly implements BeforeExecutionGenerator, may also implement ExportableProducer. For the sake of convenience, PersistentIdentifierGenerator extends ExportableProducer, in case the implementation needs to export objects to the database as part of the process of schema export.

The configure(Type, Properties, ServiceRegistry) method accepts a properties object containing named values. These include:

Instances of IdentifierGenerator are usually created and configured by the IdentifierGeneratorFactory service. It's not usually correct to use an IdentifierGenerator with the IdGeneratorType meta-annotation.

Author:
Gavin King
See Also:
  • Field Details

  • Method Details

    • configure

      default void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry)
      Configure this instance, given the value of parameters specified by the user as <param> elements.

      This method is called just once, following instantiation, and before registerExportables(Database).

      Specified by:
      configure in interface Configurable
      Parameters:
      type - The id property type descriptor
      parameters - param values, keyed by parameter name
      serviceRegistry - Access to service that may be needed.
      Throws:
      MappingException - If configuration fails.
    • registerExportables

      default void registerExportables(Database database)
      Register database objects used by this identifier generator, for example, a sequence or tables.

      This method is called just once, after configure(Type, Properties, ServiceRegistry).

      Specified by:
      registerExportables in interface ExportableProducer
      Parameters:
      database - The database instance
    • generate

      Object generate(SharedSessionContractImplementor session, Object object)
      Generate a new identifier.
      Parameters:
      session - The session from which the request originates
      object - the entity or collection (idbag) for which the id is being generated
      Returns:
      a new identifier
      Throws:
      HibernateException - Indicates trouble generating the identifier
    • generate

      default Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType)
      Generate a value.

      The currentValue is usually null for id generation.

      Specified by:
      generate in interface BeforeExecutionGenerator
      Parameters:
      session - The session from which the request originates.
      owner - The instance of the object owning the attribute for which we are generating a value.
      currentValue - The current value assigned to the property, or null
      eventType - The type of event that has triggered generation of a new value
      Returns:
      The generated value
    • getEventTypes

      default 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:
      EventTypeSets.INSERT_ONLY
    • supportsJdbcBatchInserts

      @Deprecated(since="6.2") default boolean supportsJdbcBatchInserts()
      Deprecated.
      this method is no longer called
      Check if JDBC batch inserts are supported.
      Returns:
      JDBC batch inserts are supported.