Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Extend existing Kotlin\JOOQ query with two tables with two fields, one of them I get the error Type Mismatch: required List<DATACLASS> found unit

33 views
Skip to first unread message

Nico van de Kamp

unread,
Sep 29, 2024, 5:42:23 PM9/29/24
to jOOQ User Group
As in the subject said I have two tables to extend with two fields.
The first tables could I do without issue!
The second one I'm running into trouble. 
I have changed the the database with UUID field and an Boolean field.
I run JooQGenerate, I see in the generated JOOQ files that the fields are added, I see methods to get value's from another table by FK.

But if I add one field to the select query and the fetch(...) mapping, it's compiling\running. 
If add the second field to the select\mapping, I get the error Type Mismatch required....
If I commented out one of the existing fields in the select\mapping it is compiling again. 
So it seems to me that is not direct related to the new Boolean field but which I added as new field.
(And as said I have added these two fields to another table and is compiling\running without issue!)

In hours I'm already I think 3 days searching and I've asked other people but thay have no idea and I'm running out of options..., sorry, what is this hard to find! I've no idea what is not matching: data class? database field? the sequence of select vs. mapping (but I have checked this a few times)? What else...

I've tried to build up the Select\mapping line by line, and than suddenly at the list select\mapping it gives the error...

Here is my code, I hope that it gives an impression:
override fun getResultBySubject(
varId: VarId,
subId: SubId,
aId: AId
): List<DATACLASS> = usingDSL { context ->
context.select(
TABLE_X.ID.convertFrom { BId(it!!) },
TABLE_X.MAP2,
TABLE_X.MAP3.convertFrom { varId(it!!) },
TABLE_X.MAP4.convertFrom { it!!.toInstant() },
TABLE_X.function1.NAME.convertFrom { it!! },       // This is a new added field
TABLE_X.MAP6.convertFrom { it!!.toInstant() },
TABLE_X.function2.NAME.convertFrom { it!! },
TABLE_X.MAP8.convertFrom { it!! },                  // And this is a new added field.
TABLE_X.MAP9.convertFrom { it!! },
TABLE_X.MAP10.convertFrom { it!! },
TABLE_X.MAP11.convertFrom { note -> note?.let { RichText(it) } },
TABLE_X.MAP12.convertFrom { it!! },
fuction3(alias = TABLE_X.function),
TABLE_X.MAP14,
TABLE_X.MAP15,
TABLE_X.MAP16.convertFrom { value -> value?.let { RichText(it) } },
TABLE_X.MAP17.convertFrom { record -> record.id?.let { function(record) } },
TABLE_X.MAP18,
TABLE_X.MAP19,
function3(alias = TABLE_X.field),
DSL.row(
TABLE_X.hhrHhiType.ID,
TABLE_X.hhrHhiType.NAAM,
).mapping { id, naam -> id?.let { HhiType(HhiTypeId(it), naam!!) } },
TABLE_X.MAP22,
function(TABLE_X.field) // SELECT FIELD 23
)
.from(TABLE_X)
.leftJoin()
.on()
.where(

)
.orderBy()
.fetch(
mapping { id, map2, map2, map3, map5, map6, map7, map8, map9,
map10, map11, map12, map13, map14, map15, map16,
map17, map18, map19, map20, map21, map22, map23 ->
if (map2)
dataMainclass(
id = map1
field2 = map2
...
)
else
dataSubclas(
dataSubclass(
id = map1
field2 = map2
...
)
)

Lukas Eder

unread,
Sep 30, 2024, 4:21:46 AM9/30/24
to jooq...@googlegroups.com
Hi Nico,

Thanks for your message.

jOOQ provides type safety up to degree 22, see e.g. the biggest type safe version of the select() methods:

Once you go beyond 22 fields in a projection (or function, record, etc.), jOOQ will offer only type-unsafe variants of the API using varargs, see e.g.:

You're projecting 23 expressions, and as such will have to adapt your mapping { } at the end. There's no Records.mapping(...) for more than 22 function arguments, because that cannot be expressed in terms of a functional interface in neither Java nor kotlin. So, instead of using that API, just use the fetch(RecordMapper) overload and map the record directly, without type safety. Alternatively, you can get below the 22 limit again by nesting expressions in nested records.

For historic context, 22 was the maximum expressible degree of tuples in Scala at some point (they've fixed this in the language, though this isn't possible in Java or Kotlin), so jOOQ followed this arbitrary limitation, which is as good as any other.

I hope this helps
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/c451d5b7-8099-4920-9745-45a2f9421c53n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages