Hi
I try implementing CRUD operations with UpdateableRecords. As the primary key field in my MySQL database I use the type SQLDataType.BINARY(16).nullable(false) and for the type conversion to UUID in Java I use new ByteArrayToUUIDConverter() which implements interface Converter<T, U>.
When navigating to the edit form, I can fetch a specific record from the database with this query:
TeachingMaterial teachingMaterial = this.create
.select()
.from(TEACHING_MATERIAL)
.where(TEACHING_MATERIAL.ID.eq(uuid))
.fetchOneInto(TeachingMaterial.class);
At the end, I fetch the record into a POJO (generated by jOOQ) in order I can assign the attributes easily to the fields in my Thymeleaf template.
In the controller method, I simply call the repository method which has the following code:
public void save(TeachingMaterial teachingMaterial) {
TeachingMaterialRecord teachingMaterialRecord = this.create
.newRecord(TEACHING_MATERIAL);
teachingMaterialRecord.setName(teachingMaterial.getName());
teachingMaterialRecord.setIsActive(teachingMaterial.getIsActive());
teachingMaterialRecord.setDeletedOn(teachingMaterial.getDeletedOn());
teachingMaterialRecord.setAuthorId(teachingMaterial.getAuthorId());
teachingMaterialRecord.store();
}
Unfortunately, the store() function call here raises an error:
Field 'id' doesn't have a default value
I assume it has to do with the remark "
When loading records from POJOs, jOOQ will assume the record is a new record. It will hence attempt to INSERT it." written
here.
Isn't there a way I can use the store() function by creating/updating records created from a POJO (or maybe later by a DTO which also holds records from other tables from one-to-many/many-to-many relationships?