The jOOQ User Manual. Multiple Pages : Code generation : Advanced generator configuration : Generate : Annotations | previous : next |
The code generator supports a set of annotations on generated code, which can be turned on using the following flags. These annotations include:
-
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:
- javax.persistence.Column
- javax.persistence.Entity
- javax.persistence.GeneratedValue
- javax.persistence.GenerationType
- javax.persistence.Id
- javax.persistence.Table
- javax.persistence.UniqueConstraint
@Column
) can be used by the org.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 implement the validation spec, nor does it validate your data, but you can use third-party tools to read the jOOQ-generated validation annotations.
-
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
-
The flags governing the generation of these annotations are:
XML configuration (standalone and Maven)
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.10.0.xsd"> <generator> <generate> <jpaAnnotations>true</jpaAnnotations> <validationAnnotations>true</validationAnnotations> <springAnnotations>true</springAnnotations> </generate> </generator> </configuration>
Programmatic configuration
configuration .withGenerator(new Generator( .withGenerate(new Generate() .withJpaAnnotations(true) .withValidationAnnotations(true) .withSpringAnnotations(true))));
Gradle configuration
myConfigurationName(sourceSets.main) { generator { generate { jpaAnnotations = true validationAnnotations = true springAnnotations = true } } }