Correct there should be two BasicStakeholder objects returned from the test data. One with 4 votes and the other with 2 votes.
While debugging I set a breakpoint in the setVotes(List votes) method.

The two fields of the BasicStakeholder object "weight" and "databaseId" were set to the correct values when setVotes(List votes) was called. The votes list being passed into setVotes(List votes) is just a null value.

Some more information on what I have since tried.
I commented out the code in setVotes(List votes) so I would not get a null pointer and see what it was giving me.
But then I got a ClassCastException
Commented out
<result property="votes" resultMap="Stakeholder.votes"/>
in the "stakeMap" result map. And I get two stakeholders(which is correct) The querry would return 6 rows, but it group the stakeholders by id. So that part is working.. but if I try to include the votes it will not work.


- Eric

Code: BasicVote.java and Stakeholder.xml

------------BasicVote.java-------------
package rp.object.baseImpl;

/**
* Basic implementation of the Vote interface
*/
import rp.object.Vote;

public class BasicVote implements Vote {

private int userId;
   private int instanceId;
   private int requirementId;
   private int criteriaId;
   private int voteValue;
public BasicVote(){} public BasicVote(int userId,int instanceId,int requirementId,int criteriaId,int voteValue){
       this.userId = userId;
       this.instanceId = instanceId;
       this.requirementId = requirementId;
       this.criteriaId = criteriaId;
       this.voteValue = voteValue;
   }
/* (non-Javadoc)
    * @see rp.object.Vote#equals(rp.object.Vote)
    */
   public boolean equals(Vote vote) {
       return userId == vote.getUserId() &&
           instanceId == vote.getInstanceId() &&
           requirementId == vote.getRequirementId() &&
           criteriaId == vote.getCriteriaId() &&
           voteValue == vote.getVoteValue();
   }


/*
* Getters and setters (Auto generated)
*/
/**
    * @return
    */
   public int getCriteriaId() {
       return criteriaId;
   }

   /**
    * @return
    */
   public int getInstanceId() {
       return instanceId;
   }

   /**
    * @return
    */
   public int getRequirementId() {
       return requirementId;
   }

   /**
    * @return
    */
   public int getUserId() {
       return userId;
   }

   /**
    * @return
    */
   public int getVoteValue() {
       return voteValue;
   }

   /**
    * @param i
    */
   public void setCriteriaId(int i) {
       criteriaId = i;
   }

   /**
    * @param i
    */
   public void setInstanceId(int i) {
       instanceId = i;
   }

   /**
    * @param i
    */
   public void setRequirementId(int i) {
       requirementId = i;
   }

   /**
    * @param i
    */
   public void setUserId(int i) {
       userId = i;
   }

   /**
    * @param i
    */
   public void setVoteValue(int i) {
       voteValue = i;
   }

}



----------------Stakeholder.xml-----------------------------
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd";>

<sqlMap namespace="Stakeholder">

<resultMap id="votes" class="rp.object.baseImpl.BasicVote">
       <result property="userId" column="userId"/>
       <result property="instanceId" column="instanceId"/>
       <result property="requirementId" column="requirementId"/>
       <result property="criteriaId" column="criteriaId"/>
       <result property="voteValue" column="voteValue"/>
   </resultMap>
<resultMap id="stakeMap" class="rp.object.baseImpl.BasicStakeholder" groupBy="databaseId">
       <result property="databaseId" column="databaseId"/>
       <result property="weight" column="weight"/>
       <!--<result property="votes" resultMap="Stakeholder.votes"/>-->
   </resultMap>
<select id="getStakeholders" resultMap="stakeMap">
       SELECT v.user_id AS databaseId,
           uw.weight AS weight,
           v.user_id AS userId,
           i.instance_id AS instanceId,
           v.requirement_id AS requirementId,
           v.criteria_id AS criteriaId,
           v.value AS voteValue
       FROM vote v, user_weight uw, instance i
       WHERE i.instance_id = #value#
       AND i.instance_id = uw.instance_id
       AND i.instance_id = v.instance_id
       AND uw.user_id = v.user_id
   </select>

</sqlMap>




Jeff Butler wrote:
How many BasicStakeholder objects are returned from this query? >From your prior message with the sample result set, I would expect that two are coming back. Is that correct? Are the two non-List properties of BasicStakeholder set properly? If you're getting the correct number back, then the only problem is that the Votes list of each BasicStakeholder object is empty (or null) - correct? Jeff Butler

On 4/18/06, *Eric Bauld* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    Re: Larry

    I am using iBATIS 2.7.1
    By reversing the order of the result map definitions do you mean
    putting
    the "votes" resultmap before the "stakeMap" result map ?
    I have an updated stakeholder.xml at the end of this. But still
    getting
    the same problem with the null.

    Re: Jeff

    Sorry, groupBy="requirementId" was left over from me changing things
    trying to fix this
    The unique identifier is databaseId

    I used to have
    <resultMap id="stakeMap" class="rp.object.baseImpl.BasicStakeholder"*
    groupBy="databaseId"*>

    and I tried with that and
    <resultMap id="stakeMap" class="rp.object.baseImpl.BasicStakeholder"*
    groupBy="databaseId,weight"*>

    But still get the null being passed to the setVotes(List votes)
    instead
    of any vote data

    ------------stakeholder.xml------------------
    <?xml version="1.0" encoding="UTF-8" ?>

    <!DOCTYPE sqlMap
    PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-2.dtd";>

    <sqlMap namespace="Stakeholder">

       <resultMap id="votes" class=" rp.object.baseImpl.BasicVote">
           <result property="userId" column="userId"/>
           <result property="instanceId" column="instanceId"/>
           <result property="requirementId" column="requirementId"/>
           <result property="criteriaId" column="criteriaId"/>
           <result property="voteValue" column="voteValue"/>
       </resultMap>

       <resultMap id="stakeMap" class="
    rp.object.baseImpl.BasicStakeholder"
    groupBy="databaseId">
           <result property="databaseId" column="databaseId"/>
           <result property="weight" column="weight"/>
           <result property="votes" resultMap="Stakeholder.votes"/>
       </resultMap>

       <select id="getStakeholders" resultMap="stakeMap">
           SELECT v.user_id AS databaseId,
               uw.weight AS weight,
               v.user_id AS userId,
               i.instance_id AS instanceId,
               v.requirement_id AS requirementId,
               v.criteria_id AS criteriaId,
               v.value AS voteValue
           FROM vote v, user_weight uw, instance i
           WHERE i.instance_id = #value#
           AND i.instance_id = uw.instance_id
           AND i.instance_id = v.instance_id
           AND uw.user_id = v.user_id
       </select>

    </sqlMap>



    Jeff Butler wrote:
    > I think you should have this:
    >
    > <resultMap id="stakeMap"
    class="rp.object.baseImpl.BasicStakeholder "
    > *groupBy="databaseId, weight"*>
    >        <result property="databaseId" column="databaseId"/>
    >        <result property="weight" column="weight"/>
    >        <result property="votes" resultMap="Stakeholder.votes"/>
    >    </resultMap>
    >
    >    <resultMap id="votes" class=" rp.object.baseImpl.BasicVote ">
    >        <result property="userId" column="userId"/>
    >        <result property="instanceId" column="instanceId"/>
    >        <result property="requirementId" column="requirementId"/>
    >        <result property="criteriaId" column="criteriaId"/>
    >        <result property="voteValue" column="voteValue"/>
    >    </resultMap>
    >
    > groupBy is used to specify the fields in the current object that are
    > used to identify unique objects.  I think you want two unique
    > BasicStakeholder objects with different lists contained.  Your
    > configuration is failing because requiremnentId is not a property of
    > BasicStakehoder.
    >
    > Jeff Butler
    >
    >
    >
    >
    > On 4/18/06, *Eric Bauld* < [EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>
    > <mailto:[EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>>> wrote:
    >
    >     I have been trying to get this to work for 2 days, every
    time iBATIS
    >     loads the setVotes(List votes) method in BasicStakeholder
    the list
    >     that
    >     is pass in is ALWAYS null no matter what changes I make.
    >
    >     It may be worth noting I get the same result if I put <result
    >     property="votes" resultMap="Stakeholder.votes"/>
    >     to <result property="votes" resultMap="I can put anything
    here"/> And
    >     get the same result.
    >
    >     I have the following data from this query, there are votes
    so they
    >     should be getting returned ????
    >     I debuged with a breakpoint on the setVotes() method and the
    >     BasicStakeholder object was loaded with the user id and the
    >     weight, but
    >     the list passed in was null, for the user with id of "3" and he
    >     has 4 votes.
    >
    >            SELECT v.user_id AS databaseId,
    >                uw.weight AS weight,
    >                v.user_id AS userId,
    >                i.instance_id AS instanceId,
    >                v.requirement_id AS requirementId,
    >                v.criteria_id AS criteriaId,
    >                v.value AS voteValue
    >            FROM vote v, user_weight uw, instance i
    >            WHERE i.instance_id = 1
    >            AND i.instance_id = uw.instance_id
    >            AND i.instance_id = v.instance_id
    >            AND uw.user_id = v.user_id
    >
    >     Returns
> +------------+--------+--------+------------+---------------+------------+-----------+
    >
    >     | databaseId | weight | userId | instanceId | requirementId |
    >     criteriaId
    >     | voteValue |
> +------------+--------+--------+------------+---------------+------------+-----------+
    >     |          3 |      5 |      3 |          1 |             1
    >     |          1
    >     |         9 |
    >     |          3 |      5 |      3 |          1 |             2
    >     |          1
    >     |         3 |
    >     |          3 |      5 |      3 |          1 |             3
    >     |          1
    >     |         1 |
    >     |          3 |      5 |      3 |          1 |             4
    >     |          1
    >     |         4 |
    >     |          4 |      9 |      4 |          1 |             1
    >     |          1
    >     |         9 |
    >     |          4 |      9 |      4 |          1 |             2
    >     |          1
    >     |         3 |
> +------------+--------+--------+------------+---------------+------------+-----------+

    >
    >
    >
    >     --------------------SQL MAP---------------------------------
    >     <?xml version="1.0" encoding="UTF-8" ?>
    >
    >     <!DOCTYPE sqlMap
    >     PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
    >     "http://www.ibatis.com/dtd/sql-map-2.dtd";>
    >
    >     <sqlMap namespace="Stakeholder">
    >
    >        <resultMap id="stakeMap" class="
    >     rp.object.baseImpl.BasicStakeholder"
    >     groupBy="requirementId">
    >            <result property="databaseId" column="databaseId"/>
    >            <result property="weight" column="weight"/>
    >            <result property="votes" resultMap="Stakeholder.votes"/>
    >        </resultMap>
    >
    >        <resultMap id="votes" class="rp.object.baseImpl.BasicVote ">
    >            <result property="userId" column="userId"/>
    >            <result property="instanceId" column="instanceId"/>
    >            <result property="requirementId"
    column="requirementId"/>
    >            <result property="criteriaId" column="criteriaId"/>
    >            <result property="voteValue" column="voteValue"/>
    >        </resultMap>
    >
    >
    >        <select id="getStakeholders" resultMap="stakeMap">
    >            SELECT v.user_id AS databaseId,
    >                uw.weight AS weight,
    >                 v.user_id AS userId,
    >                i.instance_id AS instanceId,
    >                v.requirement_id AS requirementId,
    >                v.criteria_id AS criteriaId,
    >                v.value AS voteValue
    >            FROM vote v, user_weight uw, instance i
    >            WHERE i.instance_id = #value#
    >            AND i.instance_id = uw.instance_id
    >            AND i.instance_id = v.instance_id
    >            AND uw.user_id = v.user_id
    >        </select>
    >
    >     </sqlMap>
    >
    >
    >



Reply via email to