Annotation Type ValueGenerationType
@Target(ANNOTATION_TYPE)@Retention(RUNTIME)public @interfaceValueGenerationType
Meta-annotation used to mark another annotation as providing configuration for a customvalue 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
insertorupdatethe entity is executed.Every generator annotation type has an
Generatorimplementation 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.
TenantIdand its corresponding generatorTenantIdGenerationare a good place to start.A
@ValueGenerationTypeannotation must have retention policyRetentionPolicy.RUNTIME.- a
Required Element Summary
Required Elements Modifier and Type Required Element Description Class<? extendsGenerator>generatedByA class which implementsGenerator.