mybatis/mybatis-3 — pull request #255 by apidevsm (2014-08-06 18:47:12+00:00)
Title: Failing Test Case : Multiple Result Sets With an Association

In beginning to use the multiple result sets functionality (which is great for the N + 1 performance issues), I have run across a case where an association is only being populated once per reference to the same data row instead of each time.
The test scenario is OrderDetail having an association to OrderHeader. If three OrderDetail instances reference the same OrderHeader row in the database, only one of the OrderDetails will have a populated association reference to its OrderHeader after retrieving the data using multiple result sets.
Doing a moderate level of tracing in the debugger, one interesting thing I observed was in the addPendingChildRelation method of org.apache.ibatis.executor.resultset.DefaultResultSetHandler.java. At line 481, a put is done to the pendingRelations map. The cacheKey (used as the map key) is generated using OrderHeader's (the To One object) hash information. The map value is the OrderDetail (the To Many object). This seems to result in an overwrite of PendingRelation instances which causes all but the last instance of OrderDetail to be lost with its pendingRelation to OrderHeader.
Thanks for considering this test case.