我正在为 ORM 框架开发 Quarkus 扩展。但是,我在使用本机模式测试时遇到了一些问题。
我收到的错误消息是:
Error: Discovered unresolved type during parsing: org.postgresql.util.PGobject. This error is reported at image build time because class xxx.xxx.xxx.sql.dialect.PostgresDialect is registered for linking at image build time by command line and command line.
更详细的错误信息如下:
Detailed message:
Error: Discovered unresolved type during parsing: org.postgresql.util.PGobject. This error is reported at image build time because class xxx.xxx.sql.dialect.PostgresDialect is registered for linking at image build time by command line and command line.
Error encountered while parsing xx.xxx.xxx.runtime.graal.Substitutions$PostgresDialectSubstitutions.unknownReader(Substitutions.java:37)
Parsing context:
at root method.(Unknown Source)
Error: Discovered unresolved type during parsing: org.postgresql.util.PGobject. This error is reported at image build time because class xxx.xxx.sql.dialect.PostgresDialect is registered for linking at image build time by command line and command line.
Error encountered while parsing xxx.xxx.sql.dialect.PostgresDialect.lambda$unknownReader$0(PostgresDialect.java:136)
Parsing context:
at static root method.(Unknown Source)
这似乎与 GraalVM 构建期间的解析过程有关,特别是与我的代码库中 PGobject 的使用有关。但是,我不确定如何解决这个问题。
以下是我的设置的简要概述:
我正在为我的应用程序使用 Quarkus 框架。 我有一个 PostgresDialect 类,其中包含一个使用 PGobject 的方法unknownReader。 我尝试了各种方法,例如用匿名类替换 lambda 表达式以及使用 GraalVM 的功能接口注册替换,但问题仍然存在。
任何人都可以深入了解为什么 GraalVM 会遇到这个“未解决的类型”问题以及如何解决它吗?任何帮助或建议将不胜感激。
以下是orm框架代码
@Override
public Reader<?> unknownReader(Class<?> sqlType) {
if (sqlType == PGobject.class) {
return (rs, col) -> rs.getObject(col.col(), PGobject.class);
}
return null;
}
这是我对 quarkus 扩展所做的事情
public class Substitutions {
@TargetClass(className = "xxx.xxx.sql.dialect.PostgresDialect")
public static final class PostgresDialectSubstitutions {
@Substitute(polymorphicSignature = true)
public Class<?> getJsonBaseType() {
return null;
}
@Substitute(polymorphicSignature = true)
public Object jsonToBaseValue(Object json, ObjectMapper objectMapper) throws Exception {
return null;
}
@Substitute(polymorphicSignature = true)
public Object baseValueToJson(Object baseValue, JavaType javaType, ObjectMapper objectMapper) throws Exception {
return null;
}
// This code is the cause of the error
@Substitute(polymorphicSignature = true)
public Reader<?> unknownReader(Class<?> sqlType) {
return null;
}
}
}
即使我的方言不是 Postgres,我仍然需要包含 Postgres 依赖项。
所以,我参考了Quarkus的代码,但是没有用。
看来无论我如何替换unknownReader方法,GraalVM仍然试图找到PGobject。
提前谢谢您!
Quarkus 应该已经处理
PGObject
https://github.com/quarkusio/quarkus/blob/214761792d5e132c28562e39e3414f2439f6b6fc/extensions/jdbc/jdbc-postgresql/deployment/src/main/java/io/quarkus/jdbc / postgresql/部署/PostgreSQLJDBCReflections.java#L13-L49
您应该检查:
quarkus-jdbc-postgresql
如果您选中了上面的所有框,您应该使用重现器向 Quarkus 项目提出问题。