Available in versions: Dev (3.20) | Latest (3.19) | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11 | 3.10
This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.
Annotations
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
The code generator supports a set of annotations on generated code, which can be turned on using the following flags. These annotations include:
-
Generated annotations: The JDK generated annotation can be added to all generated classes to include some useful meta information, like the jOOQ version, or the schema version, or the generation date. Depending on the configured
generatedAnnotationType
, the annotation is one of:-
javax.annotation.processing.Generated
(JDK 9+) -
javax.annotation.Generated
(JDK 8-)
-
-
Nullable annotations: When using alternative JVM languages like Kotlin, it may be desireable to have some hints related to nullability on generated code. When jOOQ encounters a nullable column, for instance, a JSR-305
@Nullable
annotation could warn Kotlin users about well-known nullable columns.@Nonnull
columns are more treacherous, as there are numerous reasons why a jOOQRecord
could contain anull
value in such a column, e.g. when the record was initialised without any values, or when the record originates from aUNION
orOUTER JOIN
.
ThenullableAnnotationType
andnonnullAnnotationType
configurations allow for specifying an alternative, qualified annotation name other than the JSR-305 types below.-
javax.annotation.Nullable
When a column is nullable -
javax.annotation.Nonnull
When a column is non-nullable
The additionalnullableAnnotationOnWriteOnlyNullableTypes
configuration allows for specifying whether write-only nullable columns (e.g. identities / defaulted non-null columns) should be marked as nullable as well. -
-
JPA annotations: A minimal set of JPA annotations can be generated on POJOs and other artefacts to convey type and metadata information that is available to the code generator. These annotations include:
-
jakarta.persistence.Column
-
jakarta.persistence.Entity
-
jakarta.persistence.GeneratedValue
-
jakarta.persistence.GenerationType
-
jakarta.persistence.Id
-
jakarta.persistence.Index
(JPA 2.1 and later) -
jakarta.persistence.Table
-
jakarta.persistence.UniqueConstraint
@Column
) can be used by theorg.jooq.impl.DefaultRecordMapper
for mapping records to POJOs. -
- Validation annotations: A set of Bean Validation API annotations can be added to the generated code to convey type information. They include: jOOQ does not implement the validation spec, nor does it validate your data, but you can use third-party tools to read the jOOQ-generated validation annotations.
- Bean annotations: A set of JavaBeans annotations can be added to the generated code to facilitate interoperability with the JavaBeans specification
-
Spring annotations: Some useful Spring annotations can be generated on DAOs for better Spring integration. These include:
-
org.springframework.beans.factory.annotation.Autowired
-
org.springframework.stereotype.Repository
-
org.springframework.transaction.annotation.Transactional
(if<springDao/>
is set)
-
-
Kotlin annotations: Some kotlin specific annotations may be generated in some cases. These include:
-
set:JvmName
-
The flags governing the generation of these annotations are:
<configuration> <generator> <generate> <!-- Possible values for generatedAnnotationType - DETECT_FROM_JDK - JAVAX_ANNOTATION_GENERATED - JAVAX_ANNOTATION_PROCESSING_GENERATED - ORG_JOOQ_GENERATED --> <generatedAnnotation>true</generatedAnnotation> <generatedAnnotationType>DETECT_FROM_JDK</generatedAnnotationType> <generatedAnnotationDate>true</generatedAnnotationDate> <generatedAnnotationJooqVersion>true</generatedAnnotationJooqVersion> <nullableAnnotation>true</nullableAnnotation> <nullableAnnotationOnWriteOnlyNullableTypes>true</nullableAnnotationOnWriteOnlyNullableTypes> <nullableAnnotationType>javax.annotation.Nullable</nullableAnnotationType> <nonnullAnnotation>true</nonnullAnnotation> <nonnullAnnotationType>javax.annotation.Nonnull</nonnullAnnotationType> <jpaAnnotations>true</jpaAnnotations> <jpaVersion>2.2</jpaVersion> <validationAnnotations>true</validationAnnotations> <!-- The springDao flag enables the generation of @Transactional annotations on a generated, Spring-specific DAO --> <springAnnotations>true</springAnnotations> <springDao>true</springDao> <kotlinSetterJvmNameAnnotationsOnIsPrefix>true</kotlinSetterJvmNameAnnotationsOnIsPrefix> <constructorPropertiesAnnotation>true</constructorPropertiesAnnotation> <constructorPropertiesAnnotationOnPojos>true</constructorPropertiesAnnotationOnPojos> <constructorPropertiesAnnotationOnRecords>true</constructorPropertiesAnnotationOnRecords> </generate> </generator> </configuration>
See the configuration XSD, standalone code generation, and maven code generation for more details.
new org.jooq.meta.jaxb.Configuration() .withGenerator( new Generate() // Possible values for generatedAnnotationType // - DETECT_FROM_JDK // - JAVAX_ANNOTATION_GENERATED // - JAVAX_ANNOTATION_PROCESSING_GENERATED // - ORG_JOOQ_GENERATED .withGeneratedAnnotation(true) .withGeneratedAnnotationType(GeneratedAnnotationType.DETECT_FROM_JDK) .withGeneratedAnnotationDate(true) .withGeneratedAnnotationJooqVersion(true) .withNullableAnnotation(true) .withNullableAnnotationOnWriteOnlyNullableTypes(true) .withNullableAnnotationType("javax.annotation.Nullable") .withNonnullAnnotation(true) .withNonnullAnnotationType("javax.annotation.Nonnull") .withJpaAnnotations(true) .withJpaVersion(2.2) .withValidationAnnotations(true) // The springDao flag enables the generation of @Transactional annotations on a // generated, Spring-specific DAO .withSpringAnnotations(true) .withSpringDao(true) .withKotlinSetterJvmNameAnnotationsOnIsPrefix(true) .withConstructorPropertiesAnnotation(true) .withConstructorPropertiesAnnotationOnPojos(true) .withConstructorPropertiesAnnotationOnRecords(true) )
See the configuration XSD and programmatic code generation for more details.
import org.jooq.meta.jaxb.* configuration { generator { generate { // Possible values for generatedAnnotationType // - DETECT_FROM_JDK // - JAVAX_ANNOTATION_GENERATED // - JAVAX_ANNOTATION_PROCESSING_GENERATED // - ORG_JOOQ_GENERATED isGeneratedAnnotation = true generatedAnnotationType = GeneratedAnnotationType.DETECT_FROM_JDK isGeneratedAnnotationDate = true isGeneratedAnnotationJooqVersion = true isNullableAnnotation = true isNullableAnnotationOnWriteOnlyNullableTypes = true nullableAnnotationType = "javax.annotation.Nullable" isNonnullAnnotation = true nonnullAnnotationType = "javax.annotation.Nonnull" isJpaAnnotations = true jpaVersion = 2.2 isValidationAnnotations = true // The springDao flag enables the generation of @Transactional annotations on a // generated, Spring-specific DAO isSpringAnnotations = true isSpringDao = true isKotlinSetterJvmNameAnnotationsOnIsPrefix = true isConstructorPropertiesAnnotation = true isConstructorPropertiesAnnotationOnPojos = true isConstructorPropertiesAnnotationOnRecords = true } } }
See the configuration XSD and gradle code generation for more details.
configuration { generator { generate { // Possible values for generatedAnnotationType // - DETECT_FROM_JDK // - JAVAX_ANNOTATION_GENERATED // - JAVAX_ANNOTATION_PROCESSING_GENERATED // - ORG_JOOQ_GENERATED generatedAnnotation = true generatedAnnotationType = "DETECT_FROM_JDK" generatedAnnotationDate = true generatedAnnotationJooqVersion = true nullableAnnotation = true nullableAnnotationOnWriteOnlyNullableTypes = true nullableAnnotationType = "javax.annotation.Nullable" nonnullAnnotation = true nonnullAnnotationType = "javax.annotation.Nonnull" jpaAnnotations = true jpaVersion = 2.2 validationAnnotations = true // The springDao flag enables the generation of @Transactional annotations on a // generated, Spring-specific DAO springAnnotations = true springDao = true kotlinSetterJvmNameAnnotationsOnIsPrefix = true constructorPropertiesAnnotation = true constructorPropertiesAnnotationOnPojos = true constructorPropertiesAnnotationOnRecords = true } } }
See the configuration XSD and gradle code generation for more details.
generationTool { generator { generate { // Possible values for generatedAnnotationType // - DETECT_FROM_JDK // - JAVAX_ANNOTATION_GENERATED // - JAVAX_ANNOTATION_PROCESSING_GENERATED // - ORG_JOOQ_GENERATED generatedAnnotation = true generatedAnnotationType = "DETECT_FROM_JDK" generatedAnnotationDate = true generatedAnnotationJooqVersion = true nullableAnnotation = true nullableAnnotationOnWriteOnlyNullableTypes = true nullableAnnotationType = "javax.annotation.Nullable" nonnullAnnotation = true nonnullAnnotationType = "javax.annotation.Nonnull" jpaAnnotations = true jpaVersion = 2.2 validationAnnotations = true // The springDao flag enables the generation of @Transactional annotations on a // generated, Spring-specific DAO springAnnotations = true springDao = true kotlinSetterJvmNameAnnotationsOnIsPrefix = true constructorPropertiesAnnotation = true constructorPropertiesAnnotationOnPojos = true constructorPropertiesAnnotationOnRecords = true } } }
See the configuration XSD and gradle code generation for more details.
Feedback
Do you have any feedback about this page? We'd love to hear it!