ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Butler" <jeffgbut...@gmail.com>
Subject Re: N Plus 1 Mapping Always getting a null pointer
Date Tue, 18 Apr 2006 22:17:24 GMT
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 <baulde@cpsc.ucalgary.ca> 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* <baulde@cpsc.ucalgary.ca
> > <mailto:baulde@cpsc.ucalgary.ca>> 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>
> >
> >
> >
>
>

Mime
View raw message