Reputation: 13666
Using jOOQ 3.8.6, I had to implement record mapper to convert from Record to Pojo because of some UDT in the fetched records. Now, I wonder how to do the opposite when creating a Record from a Pojo.
public void update(MyTable pojo){
MyTableRecord record = dsl.newRecord(tables.MyTable.MY_TABLE, pojo);
record.store();
}
I have a
org.jooq.exception.MappingException: An error ocurred when mapping record from class tables.pojos.MyTable
because of a
Caused by: org.jooq.exception.DataTypeException: Cannot convert from MyType (class udt.pojos.MyType) to class udt.records.MyTypeRecord
I think I have to register a custom converter from POJO to Record. Does anyone know how?
Upvotes: 6
Views: 8279
Reputation: 67
You can use ModelMapper to convert a POJO to a Record. For example:
ModelMapper modelMapper = new ModelMapper();
WorkerRecord workerRecord = modelMapper.map(worker, WorkerRecord.class);
Upvotes: 0
Reputation: 83
Ended up here with Google. As of jOOQ 3.13, the statements from OP work well.
Upvotes: 0
Reputation: 220762
You're looking for the RecordUnmapper
feature (issue #2520), which has not been implemented yet as of jOOQ 3.8
You have at least these two possible workarounds:
RecordMapper
, but a Converter
or data type Binding
instead. Those will allow you to implement the conversion in two ways, and it will not only apply to your POJOs, but also to your RecordsDSLContext.newRecord(Table, Object)
Upvotes: 2