using mysql, can create a column like:
last_modified_date timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP
So when inserting and updating, we don't need to update this column.
Thought to use readonly column in Jooq:
.withSyntheticObjects(new SyntheticObjectsType().withReadonlyColumns(
new SyntheticReadonlyColumnType().withTables("*.*").withFields("CREATED_DATE").withFields("LAST_MODIFIED_DATE")
))
The generated class has:
public final TableField<BookRecord, LocalDateTime> CREATED_DATE = createField(DSL.name("created_date"), SQLDataType.LOCALDATETIME(0).nullable(false), this, "");
When trying to use
BooksRecord rec = new BooksRecord();
rec.from(myPojo);
dslContext.batchUpdate([rec]).execute();
it will complain created_date is null if we don't set the created_date. same for the modified date.
What's the correct way of using this SyntheticReadonlyColumnType? how do I check if it is working or not? Is there a way to globally ignore those columns in update and insert sql generation?
Update: ok, seemed that the SyntheticReadonlyColumnType isn't supported in open source edition: https://www.jooq.org/doc/latest/manual/sql-building/column-expressions/readonly-columns
So the question will be what's the best way to achieve this in the open source edition? call Record.reset(Field) everytime before doing update?