Record record = dsl.newRecord(getTable(), entity);
dsl.update(getTable())
.set(record)
.where(getTableId().eq(record.getValue(getTableId())))
.execute();
and DTO Entity (id, name) - using which JOOQ record is created
This expression generates UPDATE for 3 fields (id, name, code) instead of 2.
Hence, code value in DB become null.
I would expect only 2 fields to be updated.
I tried record.changed(CODE, false), but this did not word.
Is there a way to generate update for only those columns that were actually found in DTO without manual setting them?
Regards.
--
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 jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/DIw1KfQaCs0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.
Hello, Lukas,It's great that changed() has been implemented.One more question: if a dto does not have number of fields that record has, will dsl.executeUpdate(record) on the record converted from this dto still generate update for all fields now?
--
--
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 jooq-user+...@googlegroups.com.
String sql = sl.update(TABLE1).set(record).getSQL(ParamType.INLINED);
so you can see, that sql string will contain SET statements for all fields (including DATE1), not only changed.
Regards,
Oleg
Hi Lukas,
I completely agree with your point, but it does not equal to mine :)assertFalse(record.get(record.changed(TABLE1.DATE1))) - this is correct to me.
But as a user of JOOQ, I expect that if column is not changed in record, then update SQL generated on this record will not contain 'SET date1 = null'.
My mistake - assertFalse(record.changed(TABLE1.DATE1)) - correct to me.Well, for me changed - that field was actually changed by setter. In this case it was not.I agree, stable SQL is good point, but sometimes it is necessary not to generate it in order not to erase untouched fields.Coould you comment here or on gitHub the way you solve this problem? Will changed() be always taken into account or there will be some flexibility for a progammer? The way to tell JOOQ to consider really changed field?
--
Sorry for belaboring this but I still don't see a clear answer to the question. I suppose I could just look at the code but...Many of us have beans whose fields we may populate from the database. Then a user may modify some of the field in this bean/record. When we then do an update are only the fields that have been modified updated for that row? I would expect JOOQ to only update the fields that have been modified in code, not those that were retrieved from the database and have not been "changed".
I think JOOQ cannot detect changes made in DTO, because there is no connection between it and jooq record.As I understand, since 3.6 changes made via record will cause update only changed fields.
record.store()DSL.using(configuration).update(TABLE).set(record).where(...).execute();
Also, converting DTO, where number of fields is less than in JOOQ record, to JOOQ record will also cause update only fields contained in DTO.
Hi LukasJust to clarify:>> 4. The Record.from() method simply uses reflection to take each attribute from your POJO and set the corresponding value of your record using setValue(), unless:>> a) The value is null and the corresponding Field is NOT NULLThat means that if POJO has field with null value, than record filed will be unchanged after Record.from() ? It shold be changed.
--
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 jooq-user+...@googlegroups.com.
Ok, I fixed the code a bit:Entity entityDto = new Entity(id = 1, value = null); // value is nullableString sql = dsl.update(ENTITY_RECORD).set(Record.from(entityDto)).where(...).getSql();