Annotation Interface ValueGenerationType
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
or
update
the entity is executed.
Every generator annotation type has a Generator
implementation
which is responsible for generating values. It must be either:
- a
BeforeExecutionGenerator
, for values that are generated in Java code, 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 generator
TenantIdGeneration
are a good place to start.
A @ValueGenerationType
annotation must have retention policy
RetentionPolicy.RUNTIME
.
-
Required Element Summary
Required Elements
-
Element Details
-
generatedBy
A class which implementsGenerator
.
-