Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Not all rows returned by query being mapped?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
dq  
View profile  
 More options Oct 31 2012, 5:20 pm
From: dq <d...@kayak.com>
Date: Wed, 31 Oct 2012 14:20:30 -0700 (PDT)
Local: Wed, Oct 31 2012 5:20 pm
Subject: Not all rows returned by query being mapped?

I've got a query that does a call to select a
list: getSqlSessionTemplate().selectList(query, params);

When I run the query directly against mysql, I get 2 rows returned.  When
Mybatis 3.1.1 runs it, it only returns 1 object in the list.

Here are some details, with some of the names changed to protect the
innocent.  If I happened to make a typo doing the changes, that's probably
not the source of this problem:

Here's the table:

CREATE TABLE `sanity_tests` (
  `sanity_id` int(12) unsigned NOT NULL,
  `sanitycode` char(3) NOT NULL DEFAULT '',
  `sid` int(12) unsigned NOT NULL DEFAULT '0',
  `rid` int(12) unsigned NOT NULL DEFAULT '0',
  `rcode` varchar(2) NOT NULL DEFAULT '',
  `cid` int(12) unsigned NOT NULL DEFAULT '0',
  `gid` varchar(4) NOT NULL DEFAULT '',
  PRIMARY KEY (`sanity_id`,`sanitycode`,`ctid`,`rid`,`cid`,`gid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Here's the query:

<select fetchSize="100" resultSetType="FORWARD_ONLY" id="getSanityDest"
resultMap="sanityDest">
    select sanity_id,sanitycode,sid ,rid,rcode,cid,gid from sanity_tests
  <where>
    <if test="sanityID != null" >
      AND sanity_id = #{sanityID}
    </if>
   </where>

</select>

<resultMap id="imageDest" type="com.this.that.obj.SanityDest">
  <result property="sanityId" column="sanity_id"/>
  <association property="san" resultMap="fullSanity"/>
</resultMap>

<resultMap id="fullLocation" type="com.this.that.Sanity">
 <result property="AC" column="sanitycode"/>
 <result property="sidStr" column="sid"/>
 <result property="rcode" column="rcode"/>
 <result property="ridStr" column="rid"/>
 <result property="cidStr" column="cid"/>
 <result property="gid" column="gid"/>
</resultMap>

And here's what happens when I run the select directly against the database
(mysql 5.5.24-0ubuntu0.12.04.1)

select sanity_id,sanitycode,ctid ,rid,rcode,cid,gid from sanity_tests WHERE
sanity_id =9671;
+----------+-------------+-------+------+-------+-----+-----+
| sanity_id | sanitycode | sid  | rid  | rcode | cid | gid |
+----------+-------------+-------+------+-------+-----+-----+
|     9671 | LII         | 22103 | 2500 | MM    | 201 | BB  |
|     9671 | UUU         | 13127 |  141 | MN    | 253 | SW  |
+----------+-------------+-------+------+-------+-----+-----+

I also tried running the select without speicifying the sanity_id and
mybatis seems to be only returning 1 object per sanity_id.  What's up with
that?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Larry Meadors  
View profile  
 More options Oct 31 2012, 5:29 pm
From: Larry Meadors <larry.mead...@gmail.com>
Date: Wed, 31 Oct 2012 15:28:56 -0600
Local: Wed, Oct 31 2012 5:28 pm
Subject: Re: Not all rows returned by query being mapped?

Where the sanityDest result map? This code looks messed up.

Larry


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dq  
View profile  
 More options Oct 31 2012, 5:33 pm
From: dq <d...@kayak.com>
Date: Wed, 31 Oct 2012 14:33:22 -0700 (PDT)
Local: Wed, Oct 31 2012 5:33 pm
Subject: Re: Not all rows returned by query being mapped?

Sorry, that would be the imageDest resultMap that I didn't fully obfuscate.

Does anything else look messed up besides that?  

It does correctly map a single object, it's just that it's only mapping 1
object per sanity_id returned in the resultset.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dq  
View profile  
 More options Oct 31 2012, 5:33 pm
From: dq <d...@kayak.com>
Date: Wed, 31 Oct 2012 14:33:53 -0700 (PDT)
Local: Wed, Oct 31 2012 5:33 pm
Subject: Re: Not all rows returned by query being mapped?

And likewise fullLocation should be fullSanity.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dq  
View profile  
 More options Oct 31 2012, 7:17 pm
From: dq <d...@kayak.com>
Date: Wed, 31 Oct 2012 16:17:19 -0700 (PDT)
Local: Wed, Oct 31 2012 7:17 pm
Subject: Re: Not all rows returned by query being mapped?

Here's what it looks like with those obfuscation mistakes fixed:

Here's the table:

CREATE TABLE `sanity_tests` (
  `sanity_id` int(12) unsigned NOT NULL,
  `sanitycode` char(3) NOT NULL DEFAULT '',
  `sid` int(12) unsigned NOT NULL DEFAULT '0',
  `rid` int(12) unsigned NOT NULL DEFAULT '0',
  `rcode` varchar(2) NOT NULL DEFAULT '',
  `cid` int(12) unsigned NOT NULL DEFAULT '0',
  `gid` varchar(4) NOT NULL DEFAULT '',
  PRIMARY KEY (`sanity_id`,`sanitycode`,`ctid`,`rid`,`cid`,`gid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Here's the query:

<select fetchSize="100" resultSetType="FORWARD_ONLY" id="getSanityDest"
resultMap="sanityDest">
    select sanity_id,sanitycode,sid ,rid,rcode,cid,gid from sanity_tests
  <where>
    <if test="sanityID != null" >
      AND sanity_id = #{sanityID}
    </if>
   </where>

</select>

<resultMap id="sanityDest" type="com.this.that.obj.SanityDest">
  <result property="sanityId" column="sanity_id"/>
  <association property="san" resultMap="fullSanity"/>
</resultMap>

<resultMap id="fullSanity" type="com.this.that.obj.Sanity">
 <result property="AC" column="sanitycode"/>
 <result property="sidStr" column="sid"/>
 <result property="rcode" column="rcode"/>
 <result property="ridStr" column="rid"/>
 <result property="cidStr" column="cid"/>
 <result property="gid" column="gid"/>
</resultMap>

And here's what happens when I run the select directly against the database
(mysql 5.5.24-0ubuntu0.12.04.1)

select sanity_id,sanitycode,ctid ,rid,rcode,cid,gid from sanity_tests WHERE
sanity_id =9671;
+----------+-------------+-------+------+-------+-----+-----+
| sanity_id | sanitycode | sid  | rid  | rcode | cid | gid |
+----------+-------------+-------+------+-------+-----+-----+
|     9671 | LII         | 22103 | 2500 | MM    | 201 | BB  |
|     9671 | UUU         | 13127 |  141 | MN    | 253 | SW  |
+----------+-------------+-------+------+-------+-----+-----+

Any ideas?

As I said, it's producing a result list as if I were selecting distinct on
the sanity_id


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dridi Boukelmoune  
View profile  
 More options Nov 6 2012, 5:39 am
From: Dridi Boukelmoune <dridi.boukelmo...@zenika.com>
Date: Tue, 6 Nov 2012 11:38:41 +0100
Local: Tues, Nov 6 2012 5:38 am
Subject: Re: Not all rows returned by query being mapped?
Hi,

I don't see any id in your result maps, only results.

Does "sanity_tests" have a composite id ?
* sanity_id
* sanitycode

According to your example, I would assume that the second line with
sanity_id 9671 overwrites the first one. Without any id, all results
are part of the unique key (it would mean that associations can't be
part of the unike key).

You could try a workaround like:
<resultMap id="sanityDest" type="com.this.that.obj.SanityDest">
  <result property="sanityId" column="sanity_id"/>
  <result column="sanitycode"/> <!-- no property -->
  <association property="san" resultMap="fullSanity"/>
</resultMap>

Or maybe:
<resultMap id="sanityDest" type="com.this.that.obj.SanityDest">
  <id property="sanityId" column="sanity_id"/>
  <id column="sanitycode"/> <!-- no property -->
  <association property="san" resultMap="fullSanity"/>
</resultMap>

I think it works with MB 3.1.1

Dridi

--
Dridi Boukelmoune
Développeur/Formateur

GSM : +33 (0)6 17 91 14 23


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dq  
View profile  
 More options Nov 6 2012, 9:42 am
From: dq <d...@kayak.com>
Date: Tue, 6 Nov 2012 06:42:10 -0800 (PST)
Local: Tues, Nov 6 2012 9:42 am
Subject: Re: Not all rows returned by query being mapped?

All the columns combined form the unique ID for the row.  In the end I just
used nested <constructor> in my resultMaps.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
eric  
View profile  
 More options Jan 9, 6:58 pm
From: eric <ericjnow...@gmail.com>
Date: Wed, 9 Jan 2013 15:58:58 -0800 (PST)
Local: Wed, Jan 9 2013 6:58 pm
Subject: Re: Not all rows returned by query being mapped?

Can you post your resultMaps? I'm having a similar problem but when I
attempt to use <constructor> elements in my resultMaps I get "column not
found" errors.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
eric  
View profile  
 More options Jan 9, 7:58 pm
From: eric <ericjnow...@gmail.com>
Date: Wed, 9 Jan 2013 16:58:16 -0800 (PST)
Local: Wed, Jan 9 2013 7:58 pm
Subject: Re: Not all rows returned by query being mapped?

I think I found the issue with my resultMap. I'm doing an association
select on one of the nested objects in my resultMap. This causes MyBatis to
attempt to look up the column from the association's resultMap in the
original resultMap. Since the original resultMap does not contain that
column, a column not found error is thrown.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »