Hello,

2013/11/17 Stanislas Nanchen <stanislas.nanc...@gmail.com>

> Hello,
>
> I want to load Records in Trees/Graphs to navigate them, and of course, i
> want to manipulate them (and change them) after loading.
> I confused "identity" and "value" by using Records directly in the
> graph/tree/set. Because they implement hashCode and equals, Records are
> really
> only the "values" that certain entities have in the database. What I want
> to put in the graph/tree are these entities themselves. Jooq has
> no "reference" type for that.
>

Aha, yes, I can see your concern, now. There had been a couple of
discussions in the past, related to Record value vs. Record identity. These
discussions were mostly initiated by Joachim Durchholz, e.g. in these
threads:

- https://groups.google.com/d/msg/jooq-user/NAOpCatRcjs/KMrV_Zu_S28J
- https://groups.google.com/d/msg/jooq-user/SAGC0FZtJrs/fkmN4INYQhQJ

jOOQ's Records implement equals() and hashCode() in a way that matches
SQL's row value expressions. This has been complemented in jOOQ 3.0, when
Record also implemented Comparable<Record>:
https://github.com/jOOQ/jOOQ/issues/2107

Actually, Records have some attributes of "identities" (they know if they
> need to insert or update); yet I cannot use them as "entities" because
> after changing they are no more equals to themselves, (their hash code
> changes).
>
> What i would really like are immutable Records to hold "values"  and some
> reference types to hold "identities".
>
> In any case, thanks for the help! I will use some reference types to make
> it work.
>

OK, fair enough

Note that using jOOQ 3.2, you can easily add custom code sections to
generated code, including generated records (I've noticed that this isn't
yet documented appropriately in the manual):
https://github.com/jOOQ/jOOQ/issues/2713

This would allow you to override equals() and hashCode() behaviour to use
only primary key values for equals() and hashCode() evaluation. If that's
too risky (it probably is), you might consider providing an external equals
and hashCode provider to the Set. It's a generally interesting topic. I
haven't found such a thing in Guava after a short search, but there's a
possibility of implementing
org.apache.commons.collections.map.AbstractHashedMap

In that class, you can just override the protected hash(), isEqualKey(),
isEqualValue(), and createEntry() methods.

Here's a related Stack Overflow question:
http://stackoverflow.com/a/20030782/521799

Cheers
Lukas

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

Reply via email to