Annotation Interface GenericGenerator


@Target({PACKAGE,TYPE,METHOD,FIELD}) @Retention(RUNTIME) @Repeatable(GenericGenerators.class) @Deprecated(since="6.5", forRemoval=true) public @interface GenericGenerator
Deprecated, for removal: This API element is subject to removal in a future version.
Use the new approach based on IdGeneratorType.
Defines a named identifier generator, usually an instance of the interface IdentifierGenerator. This allows the use of custom identifier generation strategies beyond those provided by the four basic JPA-defined generation types.

A named generator may be associated with an entity class by:

  • defining a named generator using this annotation, specifying an implementation of IdentifierGenerator using type(), then
  • annotating the identifier property of the entity with the JPA-defined @GeneratedValue annotation, and
  • using generator to specify the name() of the generator defined using this annotation.

If neither type() not strategy() is specified, Hibernate asks the dialect to decide an appropriate strategy. This is equivalent to using AUTO in JPA.

For example, if we define a generator using:

@GenericGenerator(name = "custom-generator",
                  type = org.hibernate.eg.CustomStringGenerator.class)
}

Then we may make use of it by annotating an identifier field as follows:

@Id @GeneratedValue(generator = "custom-generator")
private String id;

The disadvantage of this approach is the use of stringly-typed names. An alternative, completely typesafe, way to declare a generator and associate it with an entity is provided by the @IdGeneratorType meta-annotation.

See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
    The name of the identifier generator.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
    Parameters to be passed to IdentifierGenerator.configure(Type, Properties, ServiceRegistry) when the identifier generator is instantiated.
    Deprecated, for removal: This API element is subject to removal in a future version.
    use type() for typesafety
    Class<? extends Generator>
    Deprecated, for removal: This API element is subject to removal in a future version.
    The type of identifier generator, a class implementing Generator or, more commonly, IdentifierGenerator.
  • Element Details

    • name

      String name
      Deprecated, for removal: This API element is subject to removal in a future version.
      The name of the identifier generator. This is the name that may be specified by the generator member of the @GeneratedValue annotation.
      See Also:
    • type

      Class<? extends Generator> type
      Deprecated, for removal: This API element is subject to removal in a future version.
      The type of identifier generator, a class implementing Generator or, more commonly, IdentifierGenerator.
      Since:
      6.2
      Default:
      org.hibernate.generator.Generator.class
    • strategy

      @Deprecated(since="6.2", forRemoval=true) String strategy
      Deprecated, for removal: This API element is subject to removal in a future version.
      use type() for typesafety
      The type of identifier generator, the name of either:
      Default:
      "native"
    • parameters

      Parameter[] parameters
      Deprecated, for removal: This API element is subject to removal in a future version.
      Parameters to be passed to IdentifierGenerator.configure(Type, Properties, ServiceRegistry) when the identifier generator is instantiated.
      Default:
      {}