views:

394

answers:

1

Hi,

I am wondering if JdbcTemplate and RowMapper supports complex object retrieval. I couldn't find anything with google on this matter (Wrong criteria?). :(

Example:

public class Person() {
    private Long id;
    private String name;
    private PersonDetail personDetail;
}

public class PersonDetail() {
    ...
}

Tables will look the same as the objects.

What I would like to do is the following: Create a PersonRowMapper, within the mapper PersonalDetail will be also mapped as an object (what hibernate will do for you if you have a relationship defined).

Many thanks, Firone

A: 

Sure...only, you'll have to make sure your query handles the joins and all the required values in the select clause, then set personDetail's fields just as you would Person's (after instantianting a new PersonDetail).

If you wanted to have a list of PersonDetails and inflate them (i.e., one to many), JdbcTemplate can make the machanics and syntax simpler but you will have to handle the relationship and its queries fairly manually. Or use Hibernate.

tpierzina