arnaudroger / SimpleFlatMapper

Fast and Easy mapping from database and csv to POJO. A java micro ORM, lightweight alternative to iBatis and Hibernate. Fast Csv Parser and Csv Mapper
http://simpleflatmapper.org
MIT License
435 stars 76 forks source link

How would I make multiple one to many relationships work? #704

Closed Yuri-Harel closed 4 years ago

Yuri-Harel commented 4 years ago

I attempted unsuccessfully for now, to have multiple one to many relationships on an object map successfully. The issue I have every List has only a single item, and so I have a top level object for each inner object.

I did sort by first the keys, since the main object had only a complex key and then on the key I created by concating those multiple fields, simply for testing.

As an example, I have a UniversityClass instance will have a List and List, I think this is especially problematic, because I'm not sure how to order the resulting rows. According to this, it can : https://simpleflatmapper.org/0203-joins.html

Do I have to have a single column id on the UniversityClass object, or can the key be composed of multiple fields ?

Edit: After removing the other lists, it seems I just have an issue with the many to one relationship. Do you have a suggestion on a good way for me to debug this ?

Yuri-Harel commented 4 years ago

Okay, I found my issue. I was using a RowMapper instead of a ResultSetExtractor, or rather for posterity, one should go :

JdbcTemplateMapperFactory
        .newInstance()
        .addKeys("id_column", "inner_object_id_column")
        .newResultSetExtractor(SomeClass.class);

And it seems composite keys are supported.

arnaudroger commented 4 years ago

Yes, sorry for not responding, been traveling.