2
votes

I'm currently evaluating jOOQ. And we have problems with creating join statements, like this:

create.select( )
        .from( TABLEA, TABLEB)
        .where(TABLEA.ID.equal( TABLEB.TABLEA_ID ));

Because of a type mismatch. In the (Oracle 11g) Database TABLEA is NUMBER(22,0), but TABLEB.TABLEA_ID is NUMBER(7,0).

Therefore jOOQ generates for the first property a BigInteger field, but for the latter a Integer field.

So I tried to generate all NUMBER(.*,0) with BigInteger with the following xml:

    <forcedTypes>
        <forcedType>
          <name>DECIMAL_INTEGER</name>
          <expression>.*</expression>
          <types>NUMBER(.*,0)</types>
        </forcedType>
    </forcedTypes>

</database>

But this did not work. I still have fields with Integer as type. So what can I do about that, beside changing the table column type?

1

1 Answers

1
votes

Unfortunately #2485 is not yet implemented in jOOQ 3.4, so you cannot match length, precision, scale yet. I realise that the manual seems to indicate otherwise, which is wrong...

If this is only happening occasionally, you can also resort to manipulating data types through the jOOQ API. Here are some options:

// This will render an actual cast in the generated SQL statement
TABLEA.ID.equal( TABLEB.TABLEA_ID.cast(TABLEA.ID.getDataType()) )
TABLEA.ID.equal( TABLEB.TABLEA_ID.cast(BigInteger.class) )

// This generate a new column TABLEA_ID of type NUMBER(22, 0)
TABLEA.ID.equal( TABLEB.TABLEA_ID.coerce(TABLEA.ID.getDataType()) )
TABLEA.ID.equal( TABLEB.TABLEA_ID.coerce(BigInteger.class) )

// This is your last resort: raw types
TABLEA.ID.equal( (Field) TABLEB.TABLEA_ID )