У меня есть следующая конфигурация, которая хорошо работает для меня:
return new org.jooq.meta.jaxb.Configuration()
.withJdbc(new Jdbc()
.withDriver(dataSourceDriver)
.withUrl(dataSourceUrl)
.withUser(username)
.withPassword(password))
.withGenerator(new Generator()
.withName(CustomJooqGenerator.class.getCanonicalName())
// Generation options, see: https://www.jooq.org/doc/3.4/manual/code-generation/codegen-advanced/
.withGenerate(new Generate()
/* ******************************************
* Class/Record Generation Option
* ******************************************/
// Generate jOOQ Record classes for type-safe querying. You can turn
// this off, if you don't need "active records" for CRUD.
.withRecords(true)
// Generate POJOs in addition to Record classes for usage of the
// ResultQuery.fetchInto(Class) API.
.withPojos(true)
// Generate data access objects (DAOs) in addition to other classes.
.withDaos(true)
/* ******************************************
* Annotation Generation
* - see https://www.jooq.org/doc/3.12/manual/code-generation/codegen-advanced/codegen-config-generate/codegen-generate-annotations/
* ******************************************/
// Place the javax.annotation.Generated annotation on generated java files
// to indicate the jOOQ version used for source code. Defaults to true.
.withGeneratedAnnotation(true)
// Possible values for generatedAnnotationType:
// DETECT_FROM_JDK | JAVAX_ANNOTATION_GENERATED |
// JAVAX_ANNOTATION_PROCESSING_GENERATED
.withGeneratedAnnotationType(DETECT_FROM_JDK)
// Annotate POJOs and Records with JPA annotations for increased
// compatibility and better integration with JPA/Hibernate, etc
.withJpaAnnotations(true)
.withJpaVersion("2.2")
// Annotate POJOs and Records with JSR-303 validation annotations.
.withValidationAnnotations(true)
// Spring annotations can be applied on DAOs for better Spring integration. These include:
// @Autowired, and @Repository.
.withSpringAnnotations(true))
.withDatabase(new Database()
.withName("org.jooq.meta.postgres.PostgresDatabase")
.withIncludes(".*")
.withExcludes(getExcludeList())
// Remove withSchemata to generate for every schema and catalogue.
// Currently, this has issues with type generation for the default
// catalogue, so we pass in a list of schemas we are interested in.
.withSchemata(getSchemas())
// See: https://www.jooq.org/doc/3.13/manual/code-generation/custom-data-type-bindings/
// Forces certain DB types to be mapped to Java types.
.withForcedTypes(getForcedTypes())
)
.withTarget(new Target()
.withPackageName(generatedSourcesOutputPackageName)
.withDirectory(generationOutputDir)))
;
Я знаю, что в ней отсутствуют определения некоторых полей / получателей, но, пожалуйста, игнорируйте это и мои дополнительные комментарии (они не имеют отношения к вопрос).
Я знаю, что мы можем использовать опцию withExcludes
, чтобы задать регулярное выражение, которое указывает, какие объекты базы данных мы хотим исключить из генерации базы данных. В приведенной выше конфигурации у меня есть следующая конфигурация:
.withExcludes(getExcludeList())
Это хорошо работает для полного исключения объектов базы данных из автоматически сгенерированных классов. Тем не менее, мой вопрос: есть ли вариант, который я могу использовать аналогично приведенному выше, который указывает просто исключить сгенерированный класс из включения аннотаций JPA? Я все еще хочу, чтобы эти объекты базы данных генерировали классы, но я не хочу, чтобы у них были аннотации JPA. В настоящее время я использую параметры:
.withJpaAnnotations(true)
.withJpaVersion("2.2")
Эти параметры генерируют аннотации JPA практически для всего (представления, табличные функции и т. Д. c). И я бы хотел, чтобы он не генерировался для определенных ненужных объектов базы данных.
Может быть что-то вроде:
.withJpaAnnotations(true)
.withJpaVersion("2.2")
.withJpaAnnotationsExcludes(...)