Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jooq 3.12.0 custom data type binding generated code compile errors

I used jooq in 3.7.3 and now I am upgrading to jooq 3.12.0. I am seeing compile errors in my generated code.

With jooq version 3.7.3, using https://www.jooq.org/doc/3.7/manual/code-generation/custom-data-type-bindings/. I can see my custom data binding class being used ("MySqlJsonBinding") in generated code and I do not get compile errors with the generated code.

Part of my jooq.xml:

<customTypes>
    <customType>
    <name>JsonElement</name>
    <type>com.google.gson.JsonElement</type>
    <binding>jooq.MySqlJsonBinding</binding>
    </customType>
</customTypes>
<forcedTypes>
    <forcedType>
        <name>JsonElement</name>
        <expression>board_data</expression>
        <types>JSON</types>
    </forcedType>
</forcedTypes>

Generated code: no compile errors

public final TableField<UserBoardRecord, JsonElement> BOARD_DATA = createField("board_data", org.jooq.impl.DefaultDataType.getDefaultDataType("json"), this, "", new MySqlJsonBinding());

With jooq version 3.12.0, using https://www.jooq.org/doc/latest/manual/code-generation/custom-data-type-bindings/ as my example. I am not seeing "MySqlJsonBinding" in generated code, so I am not sure it is being included.

Part of my jooq.xml:

<forcedTypes>
    <forcedType>
        <userType>com.google.gson.JsonElement</userType>
        <binding>com.samplecompany.jooq.MySqlJsonBinding</binding>
        <includeExpression>.*JSON.*</includeExpression>
        <includeTypes>.*</includeTypes>
    </forcedType>
</forcedTypes>

Generated code: no compile errors, but no MySqlJsonBinding:

public final TableField<UserBoardRecord, JSON> BOARD_DATA = createField(DSL.name("board_data"), org.jooq.impl.SQLDataType.JSON, this, "");

Lastly, I am using 3.12.0, trying to apply the approach I used for 3.7.3. I do get generated code, and it does contain MySqlJsonBinding, but it has compile errors.

Part of my jooq.xml:

<forcedTypes>
    <forcedType>
        <userType>com.google.gson.JsonElement</userType>
        <binding>com.samplecompany.jooq.MySqlJsonBinding</binding>
        <includeExpression>board_data</includeExpression>
        <includeTypes>JSON</includeTypes>
    </forcedType>
</forcedTypes>

Generated code:

public final TableField<UserBoardRecord, JsonElement> BOARD_DATA = createField(DSL.name("board_data"), org.jooq.impl.SQLDataType.JSON, this, "", new MySqlJsonBinding());

Compile errors below:

ERROR:
Error:(81, 72) java: no suitable method found for createField(org.jooq.Name,org.jooq.DataType<org.jooq.JSON>,com.samplecompany.domain.data.tables.UserBoard,java.lang.String,com.samplecompany.jooq.MySqlJsonBinding)
    method org.jooq.impl.AbstractTable.<R,T>createField(java.lang.String,org.jooq.DataType<T>,org.jooq.Table<R>) is not applicable
      (cannot infer type-variable(s) R,T
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<R,T>createField(java.lang.String,org.jooq.DataType<T>,org.jooq.Table<R>,java.lang.String) is not applicable
      (cannot infer type-variable(s) R,T
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<R,T,U>createField(java.lang.String,org.jooq.DataType<T>,org.jooq.Table<R>,java.lang.String,org.jooq.Converter<T,U>) is not applicable
      (cannot infer type-variable(s) R,T,U
        (argument mismatch; org.jooq.Name cannot be converted to java.lang.String))
    method org.jooq.impl.AbstractTable.<R,T,U>createField(java.lang.String,org.jooq.DataType<T>,org.jooq.Table<R>,java.lang.String,org.jooq.Binding<T,U>) is not applicable
      (cannot infer type-variable(s) R,T,U
        (argument mismatch; org.jooq.Name cannot be converted to java.lang.String))
    method org.jooq.impl.AbstractTable.<R,T,X,U>createField(java.lang.String,org.jooq.DataType<T>,org.jooq.Table<R>,java.lang.String,org.jooq.Converter<X,U>,org.jooq.Binding<T,X>) is not applicable
      (cannot infer type-variable(s) R,T,X,U
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<T>createField(java.lang.String,org.jooq.DataType<T>) is not applicable
      (cannot infer type-variable(s) T
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<T>createField(java.lang.String,org.jooq.DataType<T>,java.lang.String) is not applicable
      (cannot infer type-variable(s) T
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<T,U>createField(java.lang.String,org.jooq.DataType<T>,java.lang.String,org.jooq.Converter<T,U>) is not applicable
      (cannot infer type-variable(s) T,U
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<T,U>createField(java.lang.String,org.jooq.DataType<T>,java.lang.String,org.jooq.Binding<T,U>) is not applicable
      (cannot infer type-variable(s) T,U
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<T,X,U>createField(java.lang.String,org.jooq.DataType<T>,java.lang.String,org.jooq.Converter<X,U>,org.jooq.Binding<T,X>) is not applicable
      (cannot infer type-variable(s) T,X,U
        (argument mismatch; org.jooq.Name cannot be converted to java.lang.String))
    method org.jooq.impl.AbstractTable.<R,T>createField(org.jooq.Name,org.jooq.DataType<T>,org.jooq.Table<R>) is not applicable
      (cannot infer type-variable(s) R,T
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<R,T>createField(org.jooq.Name,org.jooq.DataType<T>,org.jooq.Table<R>,java.lang.String) is not applicable
      (cannot infer type-variable(s) R,T
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<R,T,U>createField(org.jooq.Name,org.jooq.DataType<T>,org.jooq.Table<R>,java.lang.String,org.jooq.Converter<T,U>) is not applicable
      (cannot infer type-variable(s) R,T,U
        (argument mismatch; com.samplecompany.jooq.MySqlJsonBinding cannot be converted to org.jooq.Converter<T,U>))
    method org.jooq.impl.AbstractTable.<R,T,U>createField(org.jooq.Name,org.jooq.DataType<T>,org.jooq.Table<R>,java.lang.String,org.jooq.Binding<T,U>) is not applicable
      (inferred type does not conform to equality constraint(s)
        inferred: java.lang.Object
        equality constraints(s): java.lang.Object,org.jooq.JSON)
    method org.jooq.impl.AbstractTable.<R,T,X,U>createField(org.jooq.Name,org.jooq.DataType<T>,org.jooq.Table<R>,java.lang.String,org.jooq.Converter<X,U>,org.jooq.Binding<T,X>) is not applicable
      (cannot infer type-variable(s) R,T,X,U
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<T>createField(org.jooq.Name,org.jooq.DataType<T>) is not applicable
      (cannot infer type-variable(s) T
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<T>createField(org.jooq.Name,org.jooq.DataType<T>,java.lang.String) is not applicable
      (cannot infer type-variable(s) T
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<T,U>createField(org.jooq.Name,org.jooq.DataType<T>,java.lang.String,org.jooq.Converter<T,U>) is not applicable
      (cannot infer type-variable(s) T,U
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<T,U>createField(org.jooq.Name,org.jooq.DataType<T>,java.lang.String,org.jooq.Binding<T,U>) is not applicable
      (cannot infer type-variable(s) T,U
        (actual and formal argument lists differ in length))
    method org.jooq.impl.AbstractTable.<T,X,U>createField(org.jooq.Name,org.jooq.DataType<T>,java.lang.String,org.jooq.Converter<X,U>,org.jooq.Binding<T,X>) is not applicable
      (cannot infer type-variable(s) T,X,U
        (argument mismatch; com.samplecompany.domain.data.tables.UserBoard cannot be converted to java.lang.String))

Any ideas what I could be doing wrong? Thanks.

like image 947
Mule Avatar asked Sep 02 '19 16:09

Mule


1 Answers

jOOQ 3.12 introduced the new org.jooq.JSON type, which applies automatically to your generated code. Before, the type could not be mapped, and was thus generated as SQLDataType.OTHER, which corresponds to java.lang.Object

Your binding was working before, because it was probably a Binding<Object, YourType>. You will have to change this binding to Binding<JSON, YourType> to fix this.

like image 91
Lukas Eder Avatar answered Sep 22 '22 10:09

Lukas Eder