JOOQ – map a single record using RecordMapper

I am not able to use a RecordMapper mapper to map a single record retrieved via fetchOne/fetchAny.

If I use for example (like in the manual)

List<Something> list =  create.selectFrom(TABLE).fetch().map(mapper);

it works,

but if i use the same mapper for:

Something pojo = create.selectFrom(TABLE).fetchOne().map(mapper);

it doesn’t compile.

Thanks for the help


This probably has to do with generics. While takes a RecordMapper<? super R,E> argument type, takes RecordMapper<Record,E>, because Record has no recursive generic type definition for R.

In other words, if you want to reuse the same mapper for both and, unfortunately, you will need to make it a RecordMapper<Record, E>, which means you’ll lose some of the type safety on the record type.

A workaround would be to create a new result just for the sake of mapping:

Result<TableRecord> result = DSL.using(configuration).newResult(TABLE);
Something pojo =;

Leave a Reply

Your email address will not be published. Required fields are marked *