I have a custom data type converter for boolean values in Oracle DB:
public class CustomBooleanConverter implements Converter<String, Boolean>{
@Override
public Boolean from(String s) {
if (s == null) {
return null;
}
return s.equals("true");
}
@Override
public String to(Boolean aBoolean) {
if (aBoolean == null) {
return null;
}
return aBoolean.booleanValue() ? "true" : "false";
}
@Override
public Class<String> fromType() {
return String.class;
}
@Override
public Class<Boolean> toType() {
return Boolean.class;
}
}
And declare to be used in maven config like this:
<forcedType>
<userType>java.lang.Boolean</userType>
<objectType>ALL</objectType>
<converter>com.jooq.config.CustomBooleanConverter</converter> <includeExpression>.*.AMENDABLE</includeExpression>
<includeTypes>.*</includeTypes>
</forcedType>
Files Generated by JOOQ looks fine:
/**
* The column <code>TABLEXX.AMENDABLE</code>.
*/
public final TableField<TableXXRecord, Boolean> AMENDABLE = createField(DSL.name("AMENDABLE"), SQLDataType.VARCHAR(6), this, "", new CustomBooleanConverter());
But when building a dynamic query using SelectWhereStep, and adding a condition where a field is named AMENDABLE with boolean type and value true, the rendered SQL end up like this:
select alias_90892522.OTHER COLUMN,
......,
alias_90892522.AMENDABLE
from (
select OTHER COLUMN,
......,
AMENDABLE
from tableXX
) alias_90892522
where
(
"alias_90892522"."OTHER COLUMN" = '0005698'
and "alias_90892522"."AMENDABLE" = 1
)
Java code looks like:
SelectWhereStep<?> query = selectFrom(subquery.asTable);
query.where(getFilteringCondition(specs, class, table, dsl, resource));
this getFilteringCondition function returns a Condition object with boolean field and a value of true and comparator of “equal”.
Condition are added in a query wrapping a subquery
I debugged and the CustomBooleanConverter class is never called and I tried with different optional parameter for the forcedtype config but no success so far.
Any clue what I am doing wrong?
I am expecting JOOQ to use the custom converter for a boolean type when a column is named “AMENDABLE” accordingly to the configuration implemented. But JOOQ instead uses the default boolean convertion of boolean to integer (true = 1) and I am expecting a conversion of boolean to string like ( true = “true”).
that is making sql execution fail at runtime since the column is VARCHARD but JOOQ uses a NUMBER value
Julian Quintanilla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.