JOOQ -> Convert alias to datatype

Viewed 50

I have a query that returns a field of type array, and I used .as('Names'), to give it an alias. Now I need to assign this to a class. How can I convert the AliasField to datatype MutableSet?

I tried doing:

 myClass.names = record.get("Names", MutableSet::Class.java)

But this is of type mutableSet<*>! , I'll need to convert it a nullable type to MutableSet?.

1 Answers

Just keep a reference to your field expression and use that to read values from the record, e.g.:

val names = MY_COLUMN.as("names")
val record = ctx.select(names).from(...).fetchOne()
myClass.names = record.get(names)
Related