Available in versions: Dev (3.20) | Latest (3.19) | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11 | 3.10
Data type lookups
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
In a lot of cases, it's unnecessary to provide an explicit built-in data type or user-defined data type with a column expression in general, or a bind value in particular. For example, assuming a user-defined data type was attached to generated code using a forced type, or to a plain SQL template using an explicit converted data type, the following expressions can infer the user-defined data type from context:
// Comparison predicates with TableField/bind value pairs: TABLE.COLUMN.eq(new MyType(1)); // Comparison predicates with TableField/bind value pairs in row value expressions in various forms: row(TABLE.COLUMN1, TABLE.COLUMN2).eq(new MyType(1), new MyOtherType(2)); row(TABLE.COLUMN1, TABLE.COLUMN2).eq(row(new MyType(1), new MyOtherType(2)));
More complex expressions may be able to do the same thing, depending on your jOOQ version.
In some cases, however, the DataType
cannot be looked up from query context. This includes, for example, plain SQL templates:
// Plain SQL with bind values: DSL.condition("column = ?", new MyType(1)); // Plain SQL with expressions: DSL.condition("column = {0}", DSL.val(new MyType(1))); // With Class<?> literals: DSL.field("column", MyType.class);
jOOQ historically can still look up the first statically registered Converter
or Binding
for such a user-defined data type, which is why historically, these expressions may still work. Starting from jOOQ 3.19, this usage is discouraged, and a warning will be logged.
org.jooq.impl.DefaultDataType$DiscouragedStaticTypeRegistryUsage: null at org.jooq.impl.DefaultDataType.check(DefaultDataType.java) at org.jooq.impl.Val.accept(Val.java) at org.jooq.impl.AbstractBindContext.bindInternal(AbstractBindContext.java) at org.jooq.impl.AbstractBindContext.visit0(AbstractBindContext.java) at org.jooq.impl.AbstractContext.visit(AbstractContext.java) at ...
When this warning is encountered, users are encouraged to avoid the practice of relying on this lookup for the following reasons:
- There may be race conditions between usages of the user-defined data type and registrations of the
Converter
/Binding
in the static type registry - There may be multiple
Converter
orBinding
for the same user-defined typeClass<U>
(as well as race conditions between their registrations!) - A future version of jOOQ may unsupport this static type registry for user-defined types in favour of a dynamic type registry.
If you encounter this warning and think it shouldn't appear in your query (jOOQ should be able to infer the DataType
from context), or if you struggle to address the issue, please report an issue here: https://jooq.org/bug.
Feedback
Do you have any feedback about this page? We'd love to hear it!