我正在调查一个问题,在这个问题中,我们看到了与试图填充生成的Record类的jooq相关的奇怪异常,因为它使用java.sql.ResultSet::getXXX(int) (基于列索引)来获取数据,因此获得了数据类型错误。
我可以分享的堆栈跟踪部分如下所示:
Caused by: java.sql.SQLDataException: Value 'ABC' is outside of valid range for type java.lang.Byte
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:114)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:92)
at com.mysql.cj.jdbc.result.ResultSetImpl.getObject(ResultSetImpl.java:1423)
at com.mysql.cj.jdbc.result.ResultSetImpl.getByte(ResultSetImpl.java:710)
at com.zaxxer.hikari.pool.HikariProxyResultSet.getByte(HikariProxyResultSet.java)
at org.jooq.tools.jdbc.DefaultResultSet.getByte(DefaultResultSet.java:124)
at org.jooq.tools.jdbc.DefaultResultSet.getByte(DefaultResultSet.java:124)
at org.jooq.impl.CursorImpl$CursorResultSet.getByte(CursorImpl.java:688)
at org.jooq.impl.DefaultBinding$DefaultByteBinding.get0(DefaultBinding.java:1783)
at org.jooq.impl.DefaultBinding$DefaultByteBinding.get0(DefaultBinding.java:1755)
at org.jooq.impl.DefaultBinding$AbstractBinding.get(DefaultBinding.java:871)
at org.jooq.impl.CursorImpl$CursorIterator$CursorRecordInitialiser.setValue(CursorImpl.java:1725)这肯定是使用错误的列索引导致的列不匹配。
出现这个问题是因为我们在不断发展的模式上使用记录,所以底层表包含记录定义中不可用的列。
请注意,触发此操作的实际代码为:
jooq.insertInto(TABLE)
.set(TABLE.COL, "ABC")
.returning(TABLE.asterisk())
.fetchOne();这里让我有点害怕的是,如果它确实在设计上使用了列索引,这将使模式演变变得有些困难(如何从正在运行的应用程序中删除列)。
长话短说(对不起),问题是: jooq是否在jooq生成器生成的记录中使用列索引,是否有使用列名的方法?
我注意到的一件事是,当我比较https://www.jooq.org/doc/3.14/manual/code-generation/codegen-records/上的文档时,显示的生成记录与生成器实际生成的记录不匹配。文档显示了如下方法:
// Every column generates a setter and a getter
@Override
public void setId(Integer value) {
setValue(BOOK.ID, value);
}但在现实中,生成的代码看起来像(取自jOOQ-examples):
/**
* Setter for <code>PUBLIC.BOOK.ID</code>.
*/
public void setId(Integer value) {
set(0, value);
}顺便说一下,我们使用的是jooq 3.14.15。
发布于 2021-11-11 14:04:20
好吧,这是一个局部错误。导致这个问题的真正原因是我们的代码是这样写的:
jooq.insertInto(TABLE)
.set(TABLE.COL, "ABC")
.returning(TABLE.asterisk())
.fetchOne();而TABLE.asterisk()是把它搞得一团糟的原因(因为在包含额外列的数据库上,它不会返回jooq期望的结果)。幸运的是,删除它可以解决这个问题,所以我们的代码现在看起来像这样:
jooq.insertInto(TABLE)
.set(TABLE.COL, "ABC")
.returning()
.fetchOne();https://stackoverflow.com/questions/69926512
复制相似问题