Jooq: How to use a custom type as a standalone bind variable?

Created on 2 May 2019  路  2Comments  路  Source: jOOQ/jOOQ

Question

I don't understand how to use my custom type bindings to query the database...

I did set up my code generation to map Postgres' json (and jsonb) type to Jackson JsonNode.
It it working well!

I can do:

final List<JsonNode> = ctx.select(TABLE.JSON_FIELD).from(TABLE).fetch(TABLE.JSON_FIELD);

... and I would get an actual List<JsonNode>, which is great!

I can also do:

final JsonNode myJsonNodeInstance = ...;
ctx.update(TABLE).set(TABLE.JSON_FIELD, myJsonNodeInstance).where(...).execute();

However, when I am not directly doing .set(TABLE.JSON_FIELD, myJsonNodeInstance) (which would work), but actually:

final Field<jsonnode> jsonProperty = DSL.field("jsonb_set({0}, {1}, {2})", JsonNode.class, TABLE.JSON_FIELD, DSL.array("name"), myJsonNodeInstance);
this.ctx.update(...).set(TABLE.JSON_FIELD, jsonProperty).where(...),execute();

... I run into:

org.jooq.exception.SQLDialectNotSupportedException: Type class com.fasterxml.jackson.databind.node.ObjectNode is not supported in dialect DEFAULT

This DSLContext isn't aware of my custom binding... and I couldn't find anything related to registering "ForcedTypes" or "Bindings" or anything like that in org.jooq.conf.Settings.
I must either be looking at the wrong place or (most probably), be looking at the problem the wrong way.

What am I missing?

Steps to reproduce the problem:

See MCVE at ccjmne/jooq-mcve.

Versions:

  • jOOQ: 3.11.9
  • Java: 1.8.0-openjdk
  • Database (include vendor): postgres
  • JDBC Driver (include name if inofficial driver): 42.2.5
Functionality All Editions Medium Answered Support request

Most helpful comment

Thank you very much for documenting your findings here on Github. I'm sure this will be helpful to future visitors.

All 2 comments

Following @lukaseder's answer to my question in the docs (http://disq.us/p/21jc2zg), I could get it to work!

I actually used a DataType<JsonNode>, built with the Converter that "powers" the Binding used by TABLE.JSON_FIELD, and DSL#val(Object, DataType<T>) takes care of applying my binding.

Thank you very much for documenting your findings here on Github. I'm sure this will be helpful to future visitors.

Was this page helpful?
0 / 5 - 0 ratings