Annotation Type ValueGenerationType
-
@Target(ANNOTATION_TYPE) @Retention(RUNTIME) public @interface ValueGenerationType
Meta-annotation used to mark another annotation as providing configuration for a custom value generation strategy. This is the best way to work with customized value generation in Hibernate.For example, if we have a custom value generator:
public class SKUGeneration implements BeforeExecutionGenerator { public SKUGeneration(SKU sku, Member annotatedMember, GeneratorCreationContext context) { ... } ... }
Then we may also define an annotation which associates this generator with a field or property of an entity and supplies configuration parameters:
@ValueGenerationType(generatedBy = SKUGeneration.class) @Retention(RUNTIME) @Target({METHOD,FIELD}) public @interface SKU {}
and we may use it as follows:
@SKU String sku;
No more than one generator annotation may be placed on a given property.
Adding a generator annotation to an entity property causes the value of the property to be generated when any SQL statement to
insert
orupdate
the entity is executed.Every generator annotation type has an
Generator
implementation which is responsible for generating values. It must be either:- a
BeforeExecutionGenerator
, for values that are generated in Java code, using aValueGenerator
, or - an
OnExecutionGenerator
, for values which are generated by the database.
A generator annotation may have members, which are used to configure the value generator, if either:
- the value generator implements
AnnotationBasedGenerator
, or - the value generator class has a constructor with the same signature
as
AnnotationBasedGenerator.initialize(A, java.lang.reflect.Member, org.hibernate.generator.GeneratorCreationContext)
.
There are several excellent examples of the use of this machinery right here in this package.
TenantId
and its corresponding generatorTenantIdGeneration
are a good place to start.A
@ValueGenerationType
annotation must have retention policyRetentionPolicy.RUNTIME
. - a
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description Class<? extends Generator>
generatedBy
A class which implementsGenerator
.
-