Top Description Methods
org.hibernate.annotations

public @Interface GenericGenerator

extends Annotation
Annotations
@Target:PACKAGE, TYPE, METHOD, FIELD
@Retention:RUNTIME
@Repeatable:GenericGenerators
Imports
org.hibernate.generator.Generator, java.lang.annotation.Repeatable, .Retention, .Target

Defines a named identifier generator, usually an instance of the interface org.hibernate.id.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:

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.

Author
Emmanuel Bernard
See Also
jakarta.persistence.GeneratedValue

Method Summary

Modifier and TypeMethod and Description
public String
name()

The name of the identifier generator.

public Parameter[]
parameters()

Parameters to be passed to org.hibernate.id.IdentifierGenerator#configure when the identifier generator is instantiated.

public String
strategy()

Deprecated since 6.2. use type() for typesafety
The type of identifier generator, the name of either:
public Class<? extends Generator>
type()

The type of identifier generator, a class implementing Generator or, more commonly, org.hibernate.id.IdentifierGenerator.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

nameback to summary
public String name()

The name of the identifier generator. This is the name that may be specified by the generator member of the @GeneratedValue annotation.

See Also
jakarta.persistence.GeneratedValue#generator
parametersback to summary
public Parameter[] parameters()

Parameters to be passed to org.hibernate.id.IdentifierGenerator#configure when the identifier generator is instantiated.

strategyback to summary
public String strategy()

Deprecated

since 6.2.

use type() for typesafety

The type of identifier generator, the name of either:

Annotations
@Deprecated
since:6.2
typeback to summary
public Class<? extends Generator> type()

The type of identifier generator, a class implementing Generator or, more commonly, org.hibernate.id.IdentifierGenerator.

Since
6.2