SpringJdbc RowMapper for nested 1:n entities using only one query and column aliases
<p>I have many queries with many select fields and some nested entities. This a simplified version of nested entity structure:</p>

<pre><code>public class OuterEntity{
    private String name1;
    private String name2;
    private MiddleEntity middle;
    //... get/set..
 }

public class MiddleEntity{
    private String surname1;
    private String surname2;
    private InnerEntity inner;
    //... get/set..
}

public class InnerEntity{
    private String nickname1;
    private String nickname2;
    //... get/set..
}
</code></pre>

<p>All entities have 1:n relationship, so I can write a single long query to get all data. I want to avoid multiple queries to get each single entity separately.</p>

<pre><code>select 
    o.name1
    o.name2
    m.surname1
    m.surname2
    i.nickname1
    i.nickname2
from outertable o
join middletable m on m.id=o.middle
join innertable i on i.id=m.inner
</code></pre>

<p>I wish to have a RowMapper for this mapping using column names aliases that can get and nest all entity. Maybe I can describe all nesting path with columns alias:</p>

<pre><code>select 
    o.name1 as name1
    o.name2 as name1
    m.surname1 as middle_surname1
    m.surname2 as middle_surname2
    i.nickname1 as middle_inner_nickname1
    i.nickname2 as middle_inner_nickname2
from outertable o
join middletable m on m.id=o.middle
join innertable i on i.id=m.inner
</code></pre>

<p>Do you think is it possibile? Does jdbctemplate provide something for this need?</p>

<p>I'm not asking to code a new RowMapper for me, I just want to know if exists something or better solution becase I think it is a very common problem</p>

<p>My actual solution is to get entities separately (one query per entity) and map them with BeanPropertyRowMapper. Another solution could be to write a different RowMapper for each query, but I will use this as last chance because I should write many different mapper for a common logic.
ORM frameworks like Hibernate is not an option for me.</p>