Possible bug - fields called id and set_id in the same table leads to mapping strangeness

19 views
Skip to first unread message

joe.t...@educatorimpact.com

unread,
Nov 25, 2017, 8:17:52 AM11/25/17
to jOOQ User Group
I have some tables that are used to model multiple sets of things. They are roughly

table sets (set_id, ...some stuff about the sets)
table set_contents(id, set_id, some stuff about the items)

I generate Record and a Pojo classes from the tables. These generate getters and setters for the 'id' and 'setId' fields for set_contents.

When calling SetContentsRecord.into(SetContents.class) , the mapper seems to recognise both setId(long) and setSetId(long) as setters for the SetContents pojo, so the mapping breaks down.

For example, a record

SetContentsRecord(000, 111) 

gets mapped to a pojo

SetContents(111, 111) 

since the id is first set to 000, then 111 is copied into both the id and the set_id fields.

It kinda makes sense that the mapping code would recognise setId(long) and setSetId(long) as potential setters for set_id, I guess.

I'm afraid I don't have any good ideas about what a solution would look like, or really if this even counts as a bug, since auto mapping is a pretty dark art.

For me, I'm going to change my field names, but I thought others might be interested - it certainly cost me a lot of time :)

Kind regards,
Joe

Lukas Eder

unread,
Nov 28, 2017, 11:10:15 AM11/28/17
to jooq...@googlegroups.com
Hi Joe,

Thank you very much for reporting this. That's a very interesting edge case that arises from the fact that jOOQ:

- Calls all applicable "setters" according to the specification of the DefaultRecordMapper, in no particular order
- Accepts both JavaBeans compliant setters (setId() for the ID column) as well as "jOOQ style" setters (setId() or SET_ID() for the SET_ID column)

In a way, this "works as designed", even if in this particular case, it's obvious that the design is flawed. We'll have to fix this in a future minor release, by adding some flags that allow for turning off either one of the above "setter" styles:

Until then, workarounds include:

- Renaming columns as you've noticed
- Working around this particular issue on a per-table and per-into() call basis
- Implementing your own mapper and registering that as a RecordMapperProvider [1]

I hope this helps,
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages