Migrating jOOQ from 3.11 to 3.14 - struggling to debug indexing issue related to convertors/bindings for custom class to JSONB

41 views
Skip to first unread message

Sahil Dogra

unread,
Mar 27, 2023, 5:16:07 PM3/27/23
to jOOQ User Group
Hello, I am currently working on migrating jOOQ from version 3.11.3 to 3.14.9 and making all the necessary changes. For the most part, the migration is complete, but when I deploy my code and insertions/updates are made (via DSLContext's executeInsert and executeUpdate) to our Postgres DB via jOOQ DSL methods, for resources that have been created via jOOQ code generation from a production table, I am encountering an indexing issue. Screen Shot 2023-03-27 at 3.36.30 PM.pngScreen Shot 2023-03-27 at 4.25.22 PM.pngScreen Shot 2023-03-27 at 3.33.28 PM.pngScreen Shot 2023-03-27 at 3.33.28 PM.png
I have included relevant screenshots above that indicate the indexing issue (note I have intentionally omitted parts of the stack trace for privacy reasons), please ask if you have any questions. 

I am only seeing these errors occur when writing records to tables with JSONB objects for which we have implemented custom converter/bindings (following the doc: https://www.jooq.org/doc/3.14/manual/code-generation/codegen-advanced/codegen-config-database/codegen-database-forced-types/codegen-database-forced-types-binding/). 

Here is a relevant code snippet from our binding class that is very similar to the example in the documentation, was wondering if anything seemed off? Left out a couple details, but basically this binding is for generic custom List<T> and we have other classes extending it with the actual converter with to() and from() methods, where we basically just use GSON to convert between JSONB and our custom class. We have unit tests that test the converter's to() and from() methods so the issue shouldn't be arising from the converter. 

@Override
public void sql(final BindingSQLContext<List<T>> bindingSQLContext) throws SQLException {

// Depending on how you generate your SQL, you may need to explicitly distinguish
// between jOOQ generating bind variables or inlined literals.
if (bindingSQLContext.render().paramType() == ParamType.INLINED) {
bindingSQLContext.render().visit(DSL.inline(bindingSQLContext.convert(converter()).value())).sql("::jsonb");
} else {
bindingSQLContext.render().sql(bindingSQLContext.variable()).sql("?::jsonb");
}
}

@Override
public void register(final BindingRegisterContext<List<T>> bindingRegisterContext)
throws SQLException {
bindingRegisterContext.statement().registerOutParameter(bindingRegisterContext.index(), Types.VARCHAR);
}

@Override
public void set(final BindingSetStatementContext<List<T>> bindingSetStatementContext)
throws SQLException {
JSONB json = bindingSetStatementContext.convert(converter()).value();
bindingSetStatementContext.statement().setString(bindingSetStatementContext.index(), json != null ? json.data() : null);
}

@Override
public void set(final BindingSetSQLOutputContext<List<T>> bindingSetSQLOutputContext)
throws SQLException {
throw new SQLFeatureNotSupportedException();
}

@Override
public void get(final BindingGetResultSetContext<List<T>> bindingGetResultSetContext)
throws SQLException {
bindingGetResultSetContext.convert(converter()).value(JSONB.valueOf(bindingGetResultSetContext.resultSet().getString(bindingGetResultSetContext.index())));
}

@Override
public void get(final BindingGetStatementContext<List<T>> bindingGetStatementContext)
throws SQLException {
bindingGetStatementContext.convert(converter()).value(JSONB.valueOf(bindingGetStatementContext.statement().getString(bindingGetStatementContext.index())));
}

@Override
public void get(final BindingGetSQLInputContext<List<T>> bindingGetSQLInputContext)
throws SQLException {
throw new SQLFeatureNotSupportedException();
}

Rob Sargent

unread,
Mar 27, 2023, 5:52:39 PM3/27/23
to jooq...@googlegroups.com
On 3/27/23 14:43, Sahil Dogra wrote:
> Hello, I am currently working on migrating jOOQ from version 3.11.3 to
> 3.14.9 and making all the necessary changes. For the most part, the
> migration is complete, but when I deploy my code and
> insertions/updates are made (via DSLContext's executeInsert and
> executeUpdate) to our Postgres DB via jOOQ DSL methods, for resources
> that have been created via jOOQ code generation from a production
> table, I am encountering an indexing issue.

(Always best to copy paste text rather than screen shots)
You might need to look at the exact classpaths in play as you run your
tests:  The code and the database disagree on at least one table so I
suspect you're pointing new code at old database or vice versa.


Lukas Eder

unread,
Mar 28, 2023, 3:01:47 AM3/28/23
to jooq...@googlegroups.com
Thank you for your message Sahil.

Can you please post the error message from the stack trace (i.e. the complete stack trace)?

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/8137e295-be48-42bd-af61-cbaccce186aan%40googlegroups.com.

Lukas Eder

unread,
Mar 28, 2023, 5:07:22 AM3/28/23
to jOOQ User Group
For the record, I'm fine with screenshots.

Sahil Dogra

unread,
Mar 28, 2023, 1:42:07 PM3/28/23
to jOOQ User Group

Thank you both for your responses, I was actually just able to figure out my issue! Changing the line 

bindingSQLContext.render().sql(bindingSQLContext.variable()).sql("?::jsonb");
to 
bindingSQLContext.render().sql("?::jsonb");

resolved it. 

Lukas Eder

unread,
Mar 28, 2023, 1:56:40 PM3/28/23
to jooq...@googlegroups.com
Ah yes, I totally missed that. Do you recall what may have been the rationale behind duplicating the variable? I don't recall any changes in jOOQ that would have produced the regression you've encountered. Did you perhaps also update the JDBC driver at the same time? Recent pgjdbc versions implemented a feature where ?? is now the way to escape the ? character if you want to use the ? operator, e.g. for JSON. See:

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.

Sahil Dogra

unread,
Mar 29, 2023, 9:34:27 AM3/29/23
to jOOQ User Group
As for the rationale - not sure on my end, I am picking up the codebase after it had initially been setup a few years ago. Thanks for your input regarding the ?? feature in recent pgjdbc versions, was not aware. 

Thanks a lot Lukas, really appreciate all the work you put in for jOOQ! 

Lukas Eder

unread,
Mar 29, 2023, 10:45:02 AM3/29/23
to jooq...@googlegroups.com
You're welcome, and thanks for your nice words.

Reply all
Reply to author
Forward
0 new messages