Hi Daniele,

The rationale behind this is easy to explain:

PersonRecord p = //... select ...assert p.getName() == "Otto";
p.setName("Otto"); //why changed flag remains true?
p.store();

Explicitly setting a value in a record means that you want this value to
appear in an INSERT / UPDATE statement. This may have desired side-effects
on triggers and other database objects. Note that there is also

p.reset();

In order to reset the changed flags and the value.

More comments inline:

2013/10/23 Daniele Antonini <[email protected]>

> Hi,
>
> I'm playing a bit with UpdatableRecords, and I'm falling into this issue:
> primary key is marked as changed also when setted value is the same of
> prevoius one.
>
> I wirte a test to reproduced the issue:
> 1) using set<columnName> of generated record
> 2) using ModelMapper (corresponds to the previous case because it uses
> generated set)
>
> This test fails:
> @Test public void test() {
>     AccountUserRecord r = ctx.fetchOne(ACCOUNT_USER,
> ACCOUNT_USER.ID.eq(1L));
>     r.setId(1L);
>     assertFalse(r.changed(ACCOUNT_USER.ID));
> }
>
> When I use setValue(Field, value) the behaviour is correct, as a matter of
> fact this test pass:
> @Test public void test() {
>     AccountUserRecord r = ctx.fetchOne(ACCOUNT_USER,
> ACCOUNT_USER.ID.eq(1L));
>     r.setValue(ACCOUNT_USER.ID, 1L);
>     assertFalse(r.changed(ACCOUNT_USER.ID));
> }
>

Hmm, yes there's a bug in the above behaviour. The two calls are not
exactly equivalent, which is not good. I'll investigate this:
https://github.com/jOOQ/jOOQ/issues/2798


> For completeness' sake I attached a full maven project to highlight the
> problem, the project require mysql.
>
> Generated AccountUserRecord.setId is the following code:
> public void setId(java.lang.Long value) {
> setValue(0, value);
> }
>
> Why use setValue(int, value) instead of setValue(Field, value)?
>

Internally, records use field indexes, not Field references. So this call
is a bit more performant than setValue(Field, value). But the logic should
still be the same (which will be investigated in #2798)

Hope this helps
Cheers
Lukas


> Is this an issue of code generator?
>
> I read https://github.com/jOOQ/jOOQ/issues/945?source=c and
> https://github.com/jOOQ/jOOQ/issues/948 but I'm still puzzled:
>
> PersonRecord p = //... select ...assert p.getName() == 
> "Otto";p.setName("Max"); //ok changed is truep.setName("Max"); // ok changed 
> is still true, change flag is not resettedp.setName("Otto"); //why changed 
> flag remains true? p.store();
>
>
> Cheers
>
> --
> Daniele
>
>
>  --
> 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].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to