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?
// Create a new record BookRecord book1 = create. newRecord(BOOK); // Insert the record: INSERT INTO BOOK (TITLE) VALUES ('1984'); book1. setTitle("1984"); book1. store(); // Update the record: UPDATE BOOK SET PUBLISHED_IN = 1984 WHERE ID = [id] book1.
A record essentially combines a list of columns ( Field ) with a corresponding list of values, each value being of the respective field's type.
POJO stands for Plain Old Java Object. It is an ordinary Java object, not bound by any special restriction other than those forced by the Java Language Specification and not requiring any classpath. POJOs are used for increasing the readability and re-usability of a program.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With