开发者

Nested query results mapped to Java data types

开发者 https://www.devze.com 2023-03-03 11:53 出处:网络
I have two tables in my Sybase database A and B. The relationship between them is one-to-many where an entry in A may have one or more entries in B associated with it (via ID).

I have two tables in my Sybase database A and B. The relationship between them is one-to-many where an entry in A may have one or more entries in B associated with it (via ID).

I am trying to replicate this relationship in Java code, where I'd have a data structure for an entry in table A that would contain a list of entries from table B associated with it. Is there a way to create some sort of mapper in S开发者_开发百科pring where I can avoid loading two result sets and then trying to consolidate them together?


Yes.

Look, for example, at MyBatis mapper (Advanced Result Mapping section in http://mybatis.googlecode.com/files/MyBatis-3-User-Guide.pdf). You can load you one-to-many structure in the single query, and of course you can integrate mybatis mapping in your spring application context.

I suppose you can get the same result with any ORM tool.

0

精彩评论

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