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:
IdentifierGenerator using type,
then
@GeneratedValue annotation,
and
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.
jakarta.persistence.GeneratedValue
| Modifier and Type | Method and Description |
|---|---|
| public String | |
| public Parameter[] | parameters()
Parameters to be passed to |
| public String | strategy()
Deprecated
since 6.2. use
The type of identifier generator, the name of either:
type() for typesafety
|
| public Class | type()
The type of identifier generator, a class implementing |
| name | back to summary |
|---|---|
| public String name() The name of the identifier generator. This is the name that may be specified by
the | |
| parameters | back to summary |
|---|---|
| public Parameter[] parameters() Parameters to be passed to | |
| strategy | back to summary |
|---|---|
| public String strategy()
The type of identifier generator, the name of either:
| |
| type | back to summary |
|---|---|
| public Class The type of identifier generator, a class implementing
| |