提问者:小点点

Jooq使用多重集进行一对多选择


我有两个表和相应的dto类:

   | Records        |       | InnerRecords|
   | name           |       | name        |
   | innerRecordsId |  <--- | id          |

我正在尝试使用以下代码实现一对多选择:

var res = dslContext
.select(Records.RECORDS.ID,
        Records.RECORDS.NAME,
        multiset(DSL.select()
            .from(InnerRecords.INNER_RECORDS)
            .where(InnerRecords.INNER_RECORDS.ID.eq(Records.RECORDS.INNERRECORDID)))
       .convertFrom(r -> r.into(InnerRecordsDto.class))
       .as("innerRecord")
).from(table).fetchInto(RecordsDto.class);

但是我得到了例外:

Caused by: org.jooq.exception.MappingException: An error ocurred when mapping record to class test.ent.Records

Caused by: org.jooq.exception.DataTypeException: No Converter found for types org.jooq.Converters$UnknownType and test.ent.InnerRecord

我做错了什么?


共1个答案

匿名用户

为了能够链接表,所使用的字段必须是相同的数据类型,例如intvarchar。在某些RDBMS中,兼容的类型将被接受,而在其他情况下,它们必须是相同的
您需要检查Records.innerRecordsId和InnerRecords.id的数据类型,然后修改其中之一。