Annotation Interface SnowflakeGeneratedId


@Retention(RUNTIME) @Target({METHOD,FIELD}) public @interface SnowflakeGeneratedId
Marks a JPA id field or property as generated by the Snowflake algorithm.

Combine with @Id on a Long field:


 @Id
 @SnowflakeGeneratedId
 private Long id;
 

Hibernate reads IdGeneratorType to discover which generator class (SnowflakeIdentifierGenerator) to instantiate and invoke whenever an entity carrying this annotation is inserted. No @GeneratedValue or @GenericGenerator is needed alongside it.

For the generator to actually produce ids, an IdGenerator must already be registered with SnowflakeIdGeneratorHolder: either automatically, by adding the snowflake-jpa-spring dependency to a Spring Boot application, or manually via SnowflakeIdGeneratorHolder.setInstance(com.fayupable.snowflake.port.IdGenerator).

See Also: