Using signed integers in JOOQ

1.5k views Asked by At

I have a problem quering in JOOQ. How can I use signed integer type in jooq as it doesn't allow to cast it to UIntegers. I got the error in this equal method.

public List<Movies> getMovie(int movid) {
    return dsl.select().from(MOVIES).where(MOVIES.MOVIE_ID.equal(movid)).limit(1).fetch().into(Movies.class);
}
1

There are 1 answers

1
Lukas Eder On BEST ANSWER

I suspect that your MOVIE_ID column is of type INTEGER UNSIGNED in your MySQL database. This is why jOOQ's code generator generated a Field<UInteger> for it. You have three options:

1. Keep using unsigned integers

You'll have to convert your movid variable to an UInteger:

MOVIES.MOVIE_ID.equal(UInteger.valueOf(movid))

... or:

MOVIES.MOVIE_ID.equal(MOVIES.MOVIE_ID.getDataType().convert(movid))

2. Stop using unsigned integers in jOOQ

You can instruct the jOOQ code generator not to generate unsigned integers.

<!-- Generate jOOU data types for your unsigned data types, which are
     not natively supported in Java.
     Defaults to true -->
<unsignedTypes>false</unsignedTypes>

Alternatively, you can also use <forcedTypes/> in the code generator configuration to enforce unsigned types for individual columns.

For details, see the relevant section in the manual

3. Stop using unsigned integers in the database

Another option is to stop using UNSIGNED data types in the database, if you prefer to use signed types, of course.