Mapping list with duplicates

33 views
Skip to first unread message

ch.zw...@gmail.com

unread,
Jun 20, 2019, 5:50:47 PM6/20/19
to SimpleFlatMapper
I'm mapping ordered entries from a 1:n relationship to a list. The table is joined along with many others, so the values from this table will show up in many rows of the select and while order is guaranteed as per ID, there may be other columns that are ordered by first. My table looks like this

+--------+------+--------+
| SRC_ID | ITEM | SEQ_NR |
+--------+------+--------+
    XX |  foo |      0 |
+--------+------+--------+
    XX |  bar |      1 |
+--------+------+--------+
    XX |  foo |      2 |
+--------+------+--------+
    YY |  bar |      0 |
+--------+------+--------+

In my mapper configuration I've found that I have to ignore both SRC_ID and SEQ_NR - otherwise they end up in the list (where I want ITEM). This is what I'm currently trying (the relevant part, from a test case, using jOOQ):

private final JdbcMapper<AResource> mapper = JdbcMapperFactory.newInstance()
.useAsm(false)
.ignorePropertyNotFound()
.addKeys(root.ID.getName())
//...
.addKeys(jListTargetFieldAliasFunction.apply(Tables.A_JLIST.SRC_ID), jListTargetFieldAliasFunction.apply(Tables.A_JLIST.SEQ_NR), jListTargetFieldAliasFunction.apply(Tables.A_JLIST.ITEM))
.ignoreColumns(jListTargetFieldAliasFunction.apply(Tables.A_JLIST.SRC_ID), jListTargetFieldAliasFunction.apply(Tables.A_JLIST.SEQ_NR))
//...
.newMapper(AResource.class)
;

The functions just prefix the column names with the according fields' name to enable mapping (they're applied in the select as well).

Unfortunately, with this setup, I only get one foo and bar each for XX. If I remove ITEM as a key, I suddenly get null value instances in a completely different array, so that doesn't seem to be an option.

Any ideas? Thank you!

Arnaud Roger

unread,
Jun 20, 2019, 6:00:10 PM6/20/19
to ch.zw...@gmail.com, SimpleFlatMapper
There is an unorderedJoin option on the factory it’s more costly but my solve the issue

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "SimpleFlatMapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleflatmapp...@googlegroups.com.
To post to this group, send email to simplefl...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/simpleflatmapper/80380f38-e6d9-4278-b9f4-e0d62d863469%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ch.zw...@gmail.com

unread,
Jun 20, 2019, 6:13:05 PM6/20/19
to SimpleFlatMapper
Thanks for the answer - unfortunately not. Still only getting two entries in my list ;-(


On Friday, June 21, 2019 at 12:00:10 AM UTC+2, Arnaud Roger wrote:
There is an unorderedJoin option on the factory it’s more costly but my solve the issue

Sent from my iPhone
To unsubscribe from this group and stop receiving emails from it, send an email to simplefl...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages