ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mukul Goyal <mg...@yahoo.com>
Subject Re: N+1 select and object references
Date Thu, 15 Sep 2005 12:50:42 GMT
Thanks for the reply. So the details are that I am creating a resultMap with a groupBy clause:
<resultMap id="ruleDetailResult" class="RuleDetail" groupBy="id">
  <result property="id" column="RuleID"/>
  <result property="ruleConstraints" resultMap="Rule.ruleConstraintResult" />
<resultMap id="ruleConstraintResult" class="RuleConstraint" >
As I am stepping through the code, the RuleDetail object gets constructed and so do the RuleConstraint
objects, as there is a 1:M relationship between RuleDetail and RuleConstraint. I put a breakpoint
in the setRuleConstraints method of the RuleDetail. I notice that the List that gets passed
in is always empty even though the RuleConstraint objects get constructed. Internally in the
setRuleConstraints I am doing the following in pseudo code:
class RuleDetail{
  private HashMap constraintMap;
  setRuleConstraints(List constraints){
      For each item in constraints, put into the constraintMap;
But, I notice that the List is always empty. So I created a temporary List that saves a reference
to the List that is passed in by the setRuleConstraints. Even though it is initially empty
when passed into the method, after the queryForObject returns, the List has values in it.
So internally Ibatis must be populating the List AFTER it sets the List on the RuleDetail,
instead of before. 
Does that make more sense?

Brandon Goodin <brandon.goodin@gmail.com> wrote:If you could provide more information
about where this behavior is in
iBatis as well as the code you are using to call it, that'd help us to
see better what you are talking about.


On 9/14/05, Mukul Goyal wrote:
> I noticed that it is required (only when you are using the N+1 solution) for
> an Object that contain other objects (1:M relationships) to have BOTH a
> getter and setter method. At first I didn't realize why this was required,
> but as I was debugging a problem I realized why. 
> If the getter returns NULL during object population, IBATIS constructs a new
> List object and calls the setter on the parent object. However, when the
> setter is called the List is empty. The IBATIS implementation banks on the
> fact that you are maintaining the object inside of your bean. After it calls
> the setter with the empty List, it then goes and populates the List. I put a
> break point in my settter method and realized that the size of the list is
> never greater than 0. This seems problematic because internally I do not
> represent the content of the data as a list. 
> Is this by design or is there a work around to this problem? 
> Thanks, 
> Mukul 
> ________________________________
> Yahoo! for Good
> Click here to donate to the Hurricane Katrina relief effort. 

Yahoo! for Good
 Click here to donate to the Hurricane Katrina relief effort. 
View raw message