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
<https://www.jooq.org/doc/latest/manual/sql-execution/fetching/pojos/>,
jOOQ will assume the record is a new record. It will hence attempt to
INSERT it.*" written here
<https://www.jooq.org/doc/latest/manual/sql-execution/crud-with-updatablerecords/simple-crud/>
.
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?
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jooq-user/e93fc9f7-7435-444b-9d60-4099c094a49an%40googlegroups.com.