You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by "Engel, Gregory A" <GA...@Tribune.com> on 2005/04/20 19:11:53 UTC
queryForList vs queryForObject
With the follwing result map using a list property "contact" works perfectly
and always returns a single value as expected.
However if I use an object property "primaryContact" I get the following
error.
--- The error occurred in
com/tms/ede/server/persistance/dao/sqlmapdao/sourcesmaps/maps/EDEProgservMap
.xml.
--- The error occurred while applying a result map.
--- Check the EDEProgservRSMap_Primary.
--- Check the result mapping for the 'primaryContact' property.
--- Cause: java.sql.SQLException: Error: executeQueryForObject returned too
many results.
Caused by: java.sql.SQLException: Error: executeQueryForObject returned too
many results.
I can't understand what's going on here. I always get a single value in the
returned list which is what I want but if I use the
same query with a query for object I get an error.
Heres the resultmap
<resultMap id="EDEProgservRSMap_Primary"
class="com.tms.ede.server.persistance.dao.sqlmapdao.sourcesmaps.vo.EDEProgse
rvVO">
<result property="id" column="progserv_id"/>
<result property="statusId" column="progserv_status_id"/>
<result property="sourceId" column="source_id"/>
<result property="curTmsCallSign" column="call_sign_text"/>
<result property="sourceName" column="source_name"/>
<result property="finderText" column="source_finder_text"/>
<!--result property="contacts" column="source_id"
select="getPrimaryContactVOBy_SourceId_PrimaryOnly"/-->
<result property="primaryContact" column="source_id"
select="getPrimaryContactVOBy_SourceId_PrimaryOnly"/>
</resultMap>
Here's the sql map...
<statement id="getPrimaryContactVOBy_SourceId_PrimaryOnly"
parameterClass="java.lang.Long"
resultClass="com.tms.ede.server.persistance.dao.sqlmapdao.sourcesmaps.vo.Pri
maryContactVO"
resultMap="PrimaryContactRSMap"
>
SELECT
source.source_id,
source_contact.contact_group_owner_id,
source_contact_group.contact_id,
contact.contact_type_id,
contact.first_name,
contact.last_name,
contact.job_title,
contact.email_address,
contact.department
FROM
source,
source_contact,
source_contact_group,
contact
WHERE
source.source_id = #value#
AND
source.source_id=source_contact.source_id
AND
source_contact.contact_group_owner_id=source_contact_group.contact_group_own
er_id
AND
source_contact_group.contact_id=contact.contact_id
AND
contact.contact_type_id = 57
</statement>
Re: queryForList vs queryForObject
Posted by 任增刚 <re...@gmail.com>.
i also meet the same problem using select in a resultmap and eagering to
know how to resolve it.
2005/4/21, Engel, Gregory A <GA...@tribune.com>:
> With the follwing result map using a list property "contact" works
perfectly
> and always returns a single value as expected.
> However if I use an object property "primaryContact" I get the following
> error.
>
> --- The error occurred in
>
com/tms/ede/server/persistance/dao/sqlmapdao/sourcesmaps/maps/EDEProgservMap.xml.
>
> --- The error occurred while applying a result map.
> --- Check the EDEProgservRSMap_Primary.
> --- Check the result mapping for the 'primaryContact' property.
> --- Cause: java.sql.SQLException: Error: executeQueryForObject returned
too
> many results.
> Caused by: java.sql.SQLException: Error: executeQueryForObject returned
too
> many results.
> I can't understand what's going on here. I always get a single value in
the
> returned list which is what I want but if I use the
> same query with a query for object I get an error.
>
> Heres the resultmap
>
> <resultMap id="EDEProgservRSMap_Primary"
> class="
com.tms.ede.server.persistance.dao.sqlmapdao.sourcesmaps.vo.EDEProgservVO">
> <result property="id" column="progserv_id"/>
> <result property="statusId" column="progserv_status_id"/>
> <result property="sourceId" column="source_id"/>
> <result property="curTmsCallSign" column="call_sign_text"/>
> <result property="sourceName" column="source_name"/>
> <result property="finderText" column="source_finder_text"/>
> <!--result property="contacts" column="source_id"
> select="getPrimaryContactVOBy_SourceId_PrimaryOnly"/-->
> <result property="primaryContact" column="source_id"
> select="getPrimaryContactVOBy_SourceId_PrimaryOnly"/>
> </resultMap>
>
> Here's the sql map...
>
> <statement id="getPrimaryContactVOBy_SourceId_PrimaryOnly"
> parameterClass="java.lang.Long"
> resultClass="
com.tms.ede.server.persistance.dao.sqlmapdao.sourcesmaps.vo.PrimaryContactVO
"
> resultMap="PrimaryContactRSMap"
> >
>
> SELECT
> source.source_id,
> source_contact.contact_group_owner_id,
> source_contact_group.contact_id,
> contact.contact_type_id,
> contact.first_name,
> contact.last_name,
> contact.job_title,
> contact.email_address,
> contact.department
> FROM
> source,
> source_contact,
> source_contact_group,
> contact
> WHERE
> source.source_id = #value#
> AND
> source.source_id=source_contact.source_id
> AND
>
source_contact.contact_group_owner_id=source_contact_group.contact_group_owner_id
> AND
> source_contact_group.contact_id=contact.contact_id
> AND
> contact.contact_type_id = 57
> </statement>
--
任增刚
Renzenggang@csii.com.cn
Renzenggang@gmail.com