I have the following mapping
@Entity
@Table(name = "table_a")
data class TableBEntity(
@Id
@Column(name = "id")
val id: Int? = null,
@Transient
val tableBList: List<TableBEntity> = listOf()
)
@Entity
@Table(name = "table_b")
data class TableBEntity(
@Id
@Column(name = "id")
val id: Int? = null,
@Column(name = "user_id")
val userId: Int? = null,
@Column(name = "amount_cents")
val amountCents: Int? = null,
)
And trying to make the following query with multiset
val test = it.select(
TABLE_A.asterisk(),
multisetAgg(
TABLE_B.USER_ID,
TABLE_B.AMOUNT_CENTS
).`as`("tableBList").convertFrom(List::class.java) { r -> r.map {
s -> TableBEntity(s[TABLE_B.USER_ID], s[TABLE_B.AMOUNT_CENTS])
}
})
.from(TABLE_A)
.join(TABLE_B)
.on(TABLE_B.ID.eq(TABLE_A.ID))
.where(TABLE_A.ID.eq(1))
val result = test.fetchInto(TableAEntity::class.java)
But when I inspect result, I get correctly the tableBlist
, but the problem is that only user id is filled, the other fields come always null, even though they are not null.
In fact, when I try to run the jooq generated sql I get the correct list in tableBList column:
The generated sql:
set @t = @@group_concat_max_len;
set @@group_concat_max_len = 4294967295;
select `table_a`.*, json_merge_preserve('[]',
concat('[',
group_concat(
json_array(`table_b`.`user_id`,
`table_b`.`amount_cents`) separator ','), ']')) as `tableBList`
from `table_a` join `table_b` on `table_b`.`id` = `table_a`.`id`
where `table_a`.`id` = 1;
set @@group_concat_max_len = @t;
And result when I execute the query directly:
id | tableBList |
---|---|
1 | [[6693, 20000], [6693, 30000], [6693, 17000], [6693, 30000], [6693, 80000]] |
As you can see, there is no null values on the list, but when I inspect the variable s on the line s -> TableBEntity(s[TABLE_B.USER_ID, TABLE_B.AMOUNT_CENTS])
, I get:
user_id | amount_cents |
---|---|
*6693 | {null} |
And result contains a list of TableB, with the correct user_id's but amount_cents always null, like the jooq is not being able to parse the list from json array [[6693, 20000], [6693, 30000], [6693, 17000], [6693, 30000], [6693, 80000]]
Am I doing something wrong or is this a possible bug from jooq + mysql?
Tried jooq 3.15.5, 3.15.4, 3.15.3 with no success. MySQL version is 8.0.23