The static DSL function(s) for row()
seem not to use the dialect used in the DSLContext.
I'm using postgres with jooq to query my database. I have a Binder for use with java objects of type InetAddress
, which I am using successfully in other parts of my application. The dialect is correctly set to postgres when using the contextual DSL (DSLContext).
However, if I try to use static functions from the DSL
class, the DEFAULT dialect is used and my Binder is not used.
Specifically, my problematic query in question looks like this:
final var existingLinkRecords = asSeq(create
.selectFrom(l)
.where(row(l.FROM_IP, l.TO_IP).in(links.map(link -> row(link.from().ip(), link.to().ip())).asJava()))
.fetch());
The previous code leads to the following exception:
org.jooq.exception.SQLDialectNotSupportedException: Type class java.net.Inet6Address is not supported in dialect DEFAULT
at org.jooq.impl.DefaultDataType.getDataType(DefaultDataType.java:884)
at org.jooq.impl.DefaultDataType.getDataType(DefaultDataType.java:823)
at org.jooq.impl.DSL.getDataType(DSL.java:21760)
at org.jooq.impl.DSL.val(DSL.java:19522)
at org.jooq.impl.Tools.field(Tools.java:1209)
at org.jooq.impl.DSL.row(DSL.java:20152)
...
The root of the problem seems to be this function from DSL:
@Deprecated
@Support
public static <T> DataType<T> getDataType(Class<T> type) {
return DefaultDataType.getDataType(SQLDialect.DEFAULT, type);
}
I could not find any way to construct RowN()
objects other than using the DSL class.
Is there any way to solve this?
The problem arises from your call to
row(link.from().ip(), link.to().ip())
Since DSL.row()
is a static method, jOOQ 3.11 currently cannot "guess" what the appropriate data type binding for your custom types is, hence the exception.
As a workaround, there are various ways to attach a data type binding to your row expression. Since you have already attached it to your row(l.FROM_IP, l.TO_IP)
columns, you can reuse those using DSL.val(Object, Field)
row(val(link.from().ip(), l.FROM_IP), val(link.to().ip(), l.TO_IP))
This should probably work out of the box in your case. I have created a feature request for this: https://github.com/jOOQ/jOOQ/issues/8517