ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lisa Jenkins <lisa.jenk...@investoranalytics.com>
Subject Re: select doubt
Date Thu, 19 Jul 2007 11:47:43 GMT
Francisco,

queryForObject can only return one row.  Try queryForMap or queryForList 
instead and it should work.



Francisco Exposito Aguilera wrote:
> Hello,
>
> I have another typical issue of a beginner!!!!!
>
> I have two tables:
>
> ELEM: id, name, atrib_id
> ATRIB: id, name, value
>
> In Elem java class I´ve defined
>
> private ArrayList<Atrib> atrib_ = new ArrayList<Atrib>();
> public void setAtrib_ (Atrib atrib) {atrib_.add(atrib);}
>
> and in sqlMap I´ve defined:
>
> <resultMap id="mapAtributos" class="atributo">
>        <result property="id" column="ID"/>
>        <result property="name" column="NAME"/>
>        <result property="value" column="VALUE"/>
> </resultMap>
>
> <resultMap id="mapElementos" class="elemento">
>        <result property="id" column="ID"/>
>        <result property="name" column="NAME"/>
>        <result property="atrib_id" column="ATRIB_ID" 
> select="getAtributos" />
> </resultMap>
>
> <select id="getElementosTransaccion" resultMap="mapElementos">
>        select * from ELEM where ATRIB_ID=#value#
> </select>
>
> <select id="getAtributos" resultMap="mapAtributos">
>        select * from ATRIB oat_oet_id=#oet_id#
> </select>
>
> All this works properly if I have only one attribute for every 
> element, but if there are two attribute for any element, the I obtain 
> the error:
>
> Cause: java.sql.SQLException: Error: executeQueryForObject returned 
> too many results.
>
> I understand the error, but I am not able to find the solution!!! How 
> could I solve it? Thanks
>
>
>> From: "Francisco Exposito Aguilera" <fcoexposito@hotmail.com>
>> Reply-To: user-java@ibatis.apache.org
>> To: user-java@ibatis.apache.org
>> Subject: RE: Issue in dynamic select
>> Date: Thu, 19 Jul 2007 07:22:17 +0000
>>
>> I can´t remove the null-option but using the wrapper class it works 
>> properly! Really thanks for solve this not-iBatis issue :)
>>
>>
>>> From: "Niels Beekman" <n.beekman@wis.nl>
>>> Reply-To: user-java@ibatis.apache.org
>>> To: <user-java@ibatis.apache.org>
>>> Subject: RE: Issue in dynamic select
>>> Date: Wed, 18 Jul 2007 23:45:33 +0200
>>>
>>> The ideal solution would be to either remove the null-option on the 
>>> column or to use a wrapper class (i.e. Integer instead of int). If 
>>> you do not want to make either modifications, you could use the 
>>> nullValue-attribute which puts a "magic" value into your bean.
>>>
>>> Niels
>>>
>>> -----Original Message-----
>>> From: Francisco Exposito Aguilera [mailto:fcoexposito@hotmail.com]
>>> Sent: woensdag 18 juli 2007 22:29
>>> To: user-java@ibatis.apache.org
>>> Subject: RE: Issue in dynamic select
>>>
>>> Yes, I know that the value, in this case, is a null. Sometimes the 
>>> value is
>>> null and sometimes the value is not null, it depends and it is 
>>> right. Then,
>>> what I want is obtain and set this value when it is not null and 
>>> avoid it
>>> when it is null. Is there any way to do it? Is it possible?
>>>
>>>
>>> >From: "Niels Beekman" <n.beekman@wis.nl>
>>> >Reply-To: user-java@ibatis.apache.org
>>> >To: <user-java@ibatis.apache.org>
>>> >Subject: RE: Issue in dynamic select
>>> >Date: Wed, 18 Jul 2007 20:52:57 +0200
>>> >
>>> >Either you are throwing the exception yourselves from the setter, 
>>> or you
>>> >are trying to map a null value into a primitive field...
>>> >
>>> >Hope this helps,
>>> >
>>> >Niels
>>> >
>>> >-----Original Message-----
>>> >From: Francisco Exposito Aguilera [mailto:fcoexposito@hotmail.com]
>>> >Sent: woensdag 18 juli 2007 17:42
>>> >To: user-java@ibatis.apache.org
>>> >Subject: Issue in dynamic select
>>> >
>>> >Hello,
>>> >
>>> >I have a table where the attribute OET_Padre is a FK which 
>>> sometimes is
>>> >null.
>>> >
>>> >I want to create a dynamic select which show all fields when 
>>> OET_Padre is
>>> >not null and all fields but this one when is null.
>>> >
>>> >I´ve created a result map:
>>> >
>>> ><resultMap id="mapElementosTransaccion"
>>> >class="ads.orquestador.modelo.Elemento">
>>> >    <result property="oetID_" column="OET_ID"/>
>>> >    <result property="oetItemId_" column="OET_ITEMID"/>
>>> >    <result property="oetClase_" column="OET_CLASE"/>
>>> >    <result property="oetVersion_" column="OET_VERSION"/>
>>> >    <result property="oetOrqId_" column="OET_ORQ_ID"/>
>>> >    <result property="oetPadre_" column="OET_PADRE"/>
>>> ></resultMap>
>>> >
>>> >and the select:
>>> >
>>> ><select id="getElementosTransaccion" 
>>> resultMap="mapElementosTransaccion"
>>> >remapResults="true">
>>> >    SELECT
>>> >        OET_ID,
>>> >        OET_ItemID,
>>> >        OET_Clase,
>>> >        OET_Version,
>>> >        OET_ORQ_ID,
>>> >        OET_PADRE
>>> >    FROM ORQ_TRANS, ORQ_ELEM_TMP
>>> >    WHERE OTR_ID=#oetOrqId_#
>>> >
>>> >but when the OET_PADRE is null I receive the error
>>> >
>>> >--- Cause: java.lang.RuntimeException: Error setting property
>>> >'setOetPadre_'
>>> >of 'ads.orquestador.modelo.Elemento@e7b3f2'.  Cause:
>>> >java.lang.IllegalArgumentException
>>> >
>>> >Can anybody help me? Thanks a lot.
>>> >
>>> >_________________________________________________________________
>>> >Acepta el reto MSN Premium: Protección para tus hijos en internet.
>>> >Descárgalo y pruébalo 2 meses gratis.
>>> >http://join.msn.com?XAPID=1697&DI=1055&HL=Footer_mailsenviados_proteccioninfantil

>>>
>>> >
>>>
>>> _________________________________________________________________
>>> Grandes éxitos, superhéroes, imitaciones, cine y TV...
>>> http://es.msn.kiwee.com/ Lo mejor para tu móvil.
>>>
>>
>> _________________________________________________________________
>> Descubre la descarga digital con MSN Music. Más de un millón de 
>> canciones. http://music.msn.es/
>>
>
> _________________________________________________________________
> Dale rienda suelta a tu tiempo libre. Mil ideas para exprimir tu ocio 
> con MSN Entretenimiento. http://entretenimiento.msn.es/
>


Mime
View raw message