Class SnowflakeIdentifierGenerator

java.lang.Object
com.fayupable.snowflake.jpa.SnowflakeIdentifierGenerator
All Implemented Interfaces:
Serializable, org.hibernate.boot.model.relational.ExportableProducer, org.hibernate.generator.BeforeExecutionGenerator, org.hibernate.generator.Generator, org.hibernate.id.Configurable, org.hibernate.id.IdentifierGenerator

public class SnowflakeIdentifierGenerator extends Object implements org.hibernate.id.IdentifierGenerator
Hibernate IdentifierGenerator that delegates id generation to whatever IdGenerator is registered in SnowflakeIdGeneratorHolder.

Consumers never instantiate this class directly. Hibernate creates it via reflection when it encounters a field or property annotated with SnowflakeGeneratedId. Because Hibernate, not Spring, owns the lifecycle of this object, constructor and field injection are not available here; the static holder lookup in generate(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object) is the only way to reach the actual, DI-configured generator.

See Also:
  • Field Summary

    Fields inherited from interface org.hibernate.id.IdentifierGenerator

    CONTRIBUTOR_NAME, ENTITY_NAME, GENERATOR_NAME, JPA_ENTITY_NAME
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    generate(org.hibernate.engine.spi.SharedSessionContractImplementor session, Object entity)
    Produces the next id for an entity about to be inserted.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.hibernate.generator.BeforeExecutionGenerator

    generatedOnExecution

    Methods inherited from interface org.hibernate.id.Configurable

    configure, initialize

    Methods inherited from interface org.hibernate.generator.Generator

    allowAssignedIdentifiers, allowMutation, generatedBeforeExecution, generatedOnExecution, generatesOnForceIncrement, generatesOnInsert, generatesOnUpdate, generatesSometimes

    Methods inherited from interface org.hibernate.id.IdentifierGenerator

    configure, generate, getEventTypes, registerExportables
  • Constructor Details

    • SnowflakeIdentifierGenerator

      public SnowflakeIdentifierGenerator()
  • Method Details

    • generate

      public Object generate(org.hibernate.engine.spi.SharedSessionContractImplementor session, Object entity)
      Produces the next id for an entity about to be inserted.
      Specified by:
      generate in interface org.hibernate.id.IdentifierGenerator
      Parameters:
      session - the current Hibernate session; unused, since id generation here has no dependency on session or transaction state
      entity - the entity instance being persisted; unused, since the id does not depend on any of the entity's field values
      Returns:
      the next Snowflake id as a boxed Long, ready to be assigned to the entity's id field by Hibernate
      Throws:
      IllegalStateException - if no IdGenerator was registered with SnowflakeIdGeneratorHolder before this entity was persisted