Unfortunately you can't do that with nested result maps that way. The problem is that the iBATIS sql map syntax doesn't allow for a way to express the shift of IDs. To build a hierarchy of nodes for example, the parent node id has to use the same column as the child node id. Because of this, iBATIS has no idea if the row is a parent or a child.
So unfortunately the only way to do this in iBATIS currently is to use nested selects (LazyLoad/N+1), or if your hierarchy is of a guaranteed depth, you can specifically identify a result map for each level. To support arbitrary depth trees, we'll probably have to introduce something like <parent>/<child> or a similar concept. There's logic that has to behave quite a bit differently to make that work. Cheers, Clinton On Fri, Mar 19, 2010 at 6:43 AM, Alexander Reelsen <a...@emplify.de> wrote: > Hi > > I am currently playing around with ibatis and stuck with bidirectional > associations/circular dependencies - after googling a little bit around my > understanding is, that it should work, when caching/lazy loading is > enabled. > > So, consider the following java classes for small example: > > > class Campaign { > Integer id; > String name; > List<Target> targets; > } > > class Target { > Integer id; > String name; > String email; > Campaign campaign; > } > > This is basically the bidirectional association. Spoken from the > application point of view something like > user.getCampaign().getUsers().get(0).getCampaign() > should work. > > From the ibatis point of view I seem not to have understand yet correctly > how to handle that. > > Here are my resultMaps > > <resultMap id="campaignTargetMap" type="Target"> > <id property="id" column="target_id" /> > <result property="name" column="target_name" /> > <result property="email" column="target_email" /> > > <association property="campaign" resultMap="campaignResultMap" /> > </resultMap> > > <resultMap id="campaignResultMap" type="Campaign"> > <id property="id" column="campaign_id" /> > <result property="name" column="campaign_name" /> > > <collection property="targets" ofType="Target" > resultMap="campaignTargetMap" /> > </resultMap> > > However I keep getting a stackoverflow error, indicating that it does not > work, when I call something like the java code above. > > Here goes the exception: > > java.lang.StackOverflowError > at > com.mysql.jdbc.ConnectionImpl.getCharsetConverter(ConnectionImpl.java:2904) > at com.mysql.jdbc.ResultSetRow.getString(ResultSetRow.java:793) > at com.mysql.jdbc.ByteArrayRow.getString(ByteArrayRow.java:72) > at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5700) > at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5577) > at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5617) > at > > org.apache.ibatis.type.StringTypeHandler.getNullableResult(StringTypeHandler.java:17) > at > org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:24) > at > > org.apache.ibatis.executor.resultset.FastResultSetHandler.getPropertyMappingValue(FastResultSetHandler.java:225) > at > > org.apache.ibatis.executor.resultset.FastResultSetHandler.applyPropertyMappings(FastResultSetHandler.java:208) > at > > org.apache.ibatis.executor.resultset.NestedResultSetHandler.getRowValue(NestedResultSetHandler.java:106) > at > > org.apache.ibatis.executor.resultset.NestedResultSetHandler.applyNestedResultMappings(NestedResultSetHandler.java:136) > at > > org.apache.ibatis.executor.resultset.NestedResultSetHandler.getRowValue(NestedResultSetHandler.java:107) > at > > org.apache.ibatis.executor.resultset.NestedResultSetHandler.applyNestedResultMappings(NestedResultSetHandler.java:136) > at > > org.apache.ibatis.executor.resultset.NestedResultSetHandler.getRowValue(NestedResultSetHandler.java:107) > > [from here the last two lines keep alternating] > > > I put a quick look at ibatis jira issues 760[1] and 427[2], but that > didn't help me so far. > > > Regards and many thanks for any insightful pointers, > Alexander > > [1] https://issues.apache.org/jira/browse/IBATIS-760 > [2] https://issues.apache.org/jira/browse/IBATIS-427 > > -- > http://www.emplify.de > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org > For additional commands, e-mail: user-java-h...@ibatis.apache.org > >