diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractRoutine.java b/jOOQ/src/main/java/org/jooq/impl/AbstractRoutine.java index 1864ee1f7f..07c3faa6a9 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractRoutine.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractRoutine.java @@ -331,7 +331,7 @@ implements @Override public final void set(Parameter parameter, Z value) { - setField(parameter, val(value, parameter.getDataType())); + setField(parameter, Tools.field(value, parameter.getDataType())); } /* diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java index 33d3071965..9e7c5cc92f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java @@ -114,7 +114,9 @@ import org.jooq.Generator; import org.jooq.Name; import org.jooq.Nullability; import org.jooq.QualifiedRecord; +import org.jooq.QueryPart; import org.jooq.SQLDialect; +import org.jooq.exception.DataTypeException; import org.jooq.exception.MappingException; import org.jooq.exception.SQLDialectNotSupportedException; import org.jooq.impl.DefaultBinding.InternalBinding; @@ -931,6 +933,32 @@ public class DefaultDataType extends AbstractDataTypeX { else if (java.util.Date.class == type) return (DataType) SQLDataType.TIMESTAMP; + + // [#16529] Help users trouble shoot this particular problem + else if (QueryPart.class.isAssignableFrom(type)) + throw new DataTypeException( + """ + Type {type} cannot be used as a bind variable type. + + This error often appears when a wrong overload is chosen, e.g. among: + + - Field someFunction(T arg1, T arg2); + - Field someFunction(Field arg1, Field arg2) + + When mixing expression arguments with bind value arguments, such as: + + someFunction(TABLE.COLUMN, "bind value") + + Then only the first overload is applicable, and in some cases, jOOQ cannot auto-wrap + the "bind value" in DSL.val("bind value") for you. Consider calling the function + like this, instead: + + someFunction(TABLE.COLUMN, DSL.val("bind value")) + + If you think this error shouldn't appear, please report it here: https://jooq.org/bug + """.replace("{type}", type.getName()) + ); + // All other data types are illegal else throw new SQLDialectNotSupportedException("Type " + type + " is not supported in dialect " + dialect);