The following runtime error popped up after upgrading my jOOQ version from 3.14 -> 3.15.3:
ERROR: column "old_values" is of type jsonb but expression is of type character varying
The code looks like:
final String jsonChanges = gson.toJson(map);
final InsertOnDuplicateStep<TicketLogRecord> insertLogs =
insertInto(LOG,
LOG.ID,
LOG.OLD_VERSION,
LOG.OLD_VALUES,
LOG.NEW_VALUES)
.select(
select(field("to_update.id", UUID.class),
field("to_update.version", Integer.class),
val("{}", JsonElement.class),
val(jsonChanges, JsonElement.class),
)
final var countUpdated =
with("to_update", "id", "version", "state_id").as(ids)
.with("update_states").as(updateWhere.returning())
.with("insert_logs").as(insertLogs.returning())
.select(count().as("updated_count"))
.from("to_update");
return using(configuration)
.fetchOne(countUpdated)
.getValue("updated_count", Integer.class);
It was resolved by casting cast(val("{}", JsonElement.class), LOG.OLD_VALUES) and likewise with NEW_VALUES on the line below it. But I'm interested in why this issue with SQL generation arose between these two minor versions?
Thanks