开发者

SpringFramework JdbcTemplate RowMapper

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.

W开发者_开发技巧hat 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜