【问题标题】:jOOQ: Code generation with mavenjOOQ:使用 maven 生成代码
【发布时间】:2016-06-12 18:01:42
【问题描述】:

早安,

我正在尝试使用 jOOQ 使用 java 进行简单的 postgreSQL 设置。现在我使用 pgadmin3 创建了一个名为 Products 的表,其中包含两列:

CREATE TABLE public."Products"
(
  id integer NOT NULL,
  username text,
  CONSTRAINT id PRIMARY KEY (id)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE public."Products"
  OWNER TO postgres;

现在,我正在尝试使用 java 与此表进行交互。我可以从 postgres 请求一个表列表,所以我知道连接有效。但是,如果我尝试进行 maven 安装(以生成为目标,我想要我的 java 类),我会收到以下错误:

[ERROR] /home/dries/workspace/postgres/target/generated-sources/jooq/org/jooq/util/maven/example/PublicFactory.java:[15,58] cannot find symbol
  symbol:   class PostgresFactory
  location: package org.jooq.util.postgres
[ERROR] /home/dries/workspace/postgres/target/generated-sources/jooq/org/jooq/util/maven/example/tables/Products.java:[12,44] cannot find symbol
  symbol:   class UpdatableTableImpl
  location: package org.jooq.impl
[ERROR] /home/dries/workspace/postgres/target/generated-sources/jooq/org/jooq/util/maven/example/Keys.java:[31,120] method createUniqueKey in class org.jooq.impl.AbstractKeys cannot be applied to given types;
  required: org.jooq.Table<R>,org.jooq.TableField<R,?>[]
  found: org.jooq.util.maven.example.tables.Products,org.jooq.TableField<org.jooq.util.maven.example.tables.records.ProductsRecord,java.lang.Integer>
  reason: cannot infer type-variable(s) R
    (argument mismatch; org.jooq.util.maven.example.tables.Products cannot be converted to org.jooq.Table<R>)
[ERROR] /home/dries/workspace/postgres/target/generated-sources/jooq/org/jooq/util/maven/example/tables/records/ProductsRecord.java:[52,66] incompatible types: org.jooq.util.maven.example.tables.Products cannot be converted to org.jooq.Table<org.jooq.util.maven.example.tables.records.ProductsRecord>
[ERROR] /home/dries/workspace/postgres/target/generated-sources/jooq/org/jooq/util/maven/example/PublicFactory.java:[83,62] cannot find symbol
  symbol:   method getSettings()
  location: class org.jooq.util.maven.example.PublicFactory
[ERROR] /home/dries/workspace/postgres/target/generated-sources/jooq/org/jooq/util/maven/example/tables/Products.java:[24,9] method does not override or implement a method from a supertype
[ERROR] /home/dries/workspace/postgres/target/generated-sources/jooq/org/jooq/util/maven/example/tables/Products.java:[34,125] cannot find symbol
  symbol:   method createField(java.lang.String,org.jooq.DataType<java.lang.Integer>,org.jooq.util.maven.example.tables.Products)
  location: class org.jooq.util.maven.example.tables.Products
[ERROR] /home/dries/workspace/postgres/target/generated-sources/jooq/org/jooq/util/maven/example/tables/Products.java:[39,130] cannot find symbol
  symbol:   method createField(java.lang.String,org.jooq.DataType<java.lang.String>,org.jooq.util.maven.example.tables.Products)
  location: class org.jooq.util.maven.example.tables.Products
[ERROR] /home/dries/workspace/postgres/target/generated-sources/jooq/org/jooq/util/maven/example/tables/Products.java:[49,9] method does not override or implement a method from a supertype
[ERROR] /home/dries/workspace/postgres/target/generated-sources/jooq/org/jooq/util/maven/example/tables/Products.java:[54,9] method does not override or implement a method from a supertype
[ERROR] /home/dries/workspace/postgres/target/generated-sources/jooq/org/jooq/util/maven/example/tables/Products.java:[60,9] method does not override or implement a method from a supertype
[ERROR] /home/dries/workspace/postgres/target/generated-sources/jooq/org/jooq/util/maven/example/Public.java:[36,40] method asList in class java.util.Arrays cannot be applied to given types;
  required: T[]
  found: org.jooq.util.maven.example.tables.Products
  reason: varargs mismatch; org.jooq.util.maven.example.tables.Products cannot be converted to org.jooq.Table<?>

似乎确实生成了该类(因为我可以在目标文件夹中找到它)。但是在 eclipse 或 intellij 中,我无法在路径中找到它。 无论哪种方式,构建过程都不应失败。

有人知道构建失败的原因吗?

谢谢,美好的一天。

【问题讨论】:

  • "PublicFactory" - 你用的是什么古老版本的 jOOQ? :) 介意先升级?另外,能否请您发布您的相关pom.xml 配置?
  • 天哪,我在 3.7.2 上为 jOOQ 但我似乎不小心从 2.6.4 复制粘贴了插件。谷歌搜索结果有时会导致文档版本过时。我将为此责怪星期一!谢谢卢卡斯 :)
  • 那么,最好期待周二!

标签: java postgresql maven jooq


【解决方案1】:

所以,为了在 Stack Overflow 上有一个正式的答案,这里再次将我的评论作为答案。

从外观上看,您使用的是过时的 jOOQ 代码生成器版本和较新的 jOOQ 运行时版本。两者不匹配,这就是你得到这些异常的原因。

我注意到 PublicFactory 类不再由 jOOQ 3.x 代码生成器生成。

【讨论】:

  • 如果你能放上最新的代码生成器样本就好了...查看文档时,我发现很多旧配置并且无法找到正确的设置(尤其是在使用 spring-boot 时) )
  • @рüффп:你能指出过时的文档吗?
  • 算了,这只是 IDEA 将插件显示为红色,但生成工作正常。似乎是因为 Idea 在 spring-boot-starter-jooq 中没有看到 ${jooq.version}。我的问题只是一个导入被丢弃并重新创建它解决了我的问题。
猜你喜欢
  • 2021-10-28
  • 2017-12-08
  • 2019-03-27
  • 2020-07-26
  • 2014-09-09
  • 2017-12-03
  • 2017-08-13
  • 2020-01-23
  • 2016-02-19
相关资源
最近更新 更多