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 Francisco Exposito Aguilera <fc...@hotmail.com> on 2007/07/19 13:44:49 UTC
select doubt
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" <fc...@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....@wis.nl>
>>Reply-To: user-java@ibatis.apache.org
>>To: <us...@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....@wis.nl>
>> >Reply-To: user-java@ibatis.apache.org
>> >To: <us...@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/
RE: select doubt
Posted by "Hemant.Kamatgi" <He...@target.com>.
Well, From your object model, I can infer that 'elem' to 'atrib' is 1:M relationship. In RDBMS,this means that atrib table has elem_id(PK of elem table) as foreign key. So, with this relationship, you can have one query with a join between the two retrieve an element and a collection of atrib for that element. The result map wud look like this:
>><resultMap id="mapElementos" class="elemento">
>> <result property="id" column="ID"/>
>> <result property="name" column="NAME"/>
>> <result property="atrib_" resultMap="namespaceName.mapAtributos " />
>></resultMap>
>><resultMap id="mapAtributos" class="atributo">
>> <result property="id" column="ID"/>
>> <result property="name" column="NAME"/>
>> <result property="value" column="VALUE"/>
>></resultMap>
Then, if the element id is known to you, you can use queryForObject to retrieve an Element and use getAtrib_() to retrieve the collection of Atribs for the element.
Hope this helps.
Regards
Hemant
-----Original Message-----
From: Francisco Exposito Aguilera [mailto:fcoexposito@hotmail.com]
Sent: Thursday, July 19, 2007 7:00 AM
To: user-java@ibatis.apache.org
Subject: Re: select doubt
Hi Lisa,
I execute elements = sqlMap.queryForList("getElements",
transac.getOtrID_());
I can obtain n elements with only one or none attribute every one.
But I want to obtain n elements of n attributes every one.
>From: Lisa Jenkins <li...@investoranalytics.com>
>Reply-To: user-java@ibatis.apache.org
>To: user-java@ibatis.apache.org
>Subject: Re: select doubt
>Date: Thu, 19 Jul 2007 07:47:43 -0400
>
>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" <fc...@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....@wis.nl>
>>>>Reply-To: user-java@ibatis.apache.org
>>>>To: <us...@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....@wis.nl>
>>>> >Reply-To: user-java@ibatis.apache.org
>>>> >To: <us...@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/
>>
>
_________________________________________________________________
Dale rienda suelta a tu tiempo libre. Mil ideas para exprimir tu ocio con
MSN Entretenimiento. http://entretenimiento.msn.es/
Re: select doubt
Posted by Francisco Exposito Aguilera <fc...@hotmail.com>.
Hi Lisa,
I execute elements = sqlMap.queryForList("getElements",
transac.getOtrID_());
I can obtain n elements with only one or none attribute every one.
But I want to obtain n elements of n attributes every one.
>From: Lisa Jenkins <li...@investoranalytics.com>
>Reply-To: user-java@ibatis.apache.org
>To: user-java@ibatis.apache.org
>Subject: Re: select doubt
>Date: Thu, 19 Jul 2007 07:47:43 -0400
>
>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" <fc...@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....@wis.nl>
>>>>Reply-To: user-java@ibatis.apache.org
>>>>To: <us...@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....@wis.nl>
>>>> >Reply-To: user-java@ibatis.apache.org
>>>> >To: <us...@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/
>>
>
_________________________________________________________________
Dale rienda suelta a tu tiempo libre. Mil ideas para exprimir tu ocio con
MSN Entretenimiento. http://entretenimiento.msn.es/
Re: select doubt
Posted by Lisa Jenkins <li...@investoranalytics.com>.
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" <fc...@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....@wis.nl>
>>> Reply-To: user-java@ibatis.apache.org
>>> To: <us...@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....@wis.nl>
>>> >Reply-To: user-java@ibatis.apache.org
>>> >To: <us...@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/
>
Re: select doubt
Posted by Francisco Exposito Aguilera <fc...@hotmail.com>.
The two changes I´ve done are:
the new set method
public void setAtrib_ (ArrayList<Atrib> atrib_) {this.atrib_ = atrib_;}
and the result property for attributes
<result property="atrib_" resultMap="Elemento.mapAtributos " />
where Elemento is the namespace of the sqlMap file, but it is in the same
sqlMap file as the <resultMap id="mapElementos" class="elemento">
If I debug the code using a breakpoint in the setAtrib_ method, I obtain
when the process arrives to the set method that the parameter atrib_ is null
and if I end the execution I get the error:
Cause: com.ibatis.sqlmap.client.SqlMapException: There is no result map
named elemento.getAtributos in this SqlMap.
In order to check if the null is caused for the select getAtributos, I´ve
call it directly from the application and it returns the correct values...
I´m lost!!! Thanks
>From: "Francisco Exposito Aguilera" <fc...@hotmail.com>
>Reply-To: user-java@ibatis.apache.org
>To: user-java@ibatis.apache.org
>Subject: Re: select doubt
>Date: Sat, 21 Jul 2007 16:06:18 +0000
>
>I´ve checked my code and I think I am doing something wrong in my
>resultMap, but I don´t know how to solve it...
>
><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>
>
>In my old resultMap I had
>
><result property="atrib_id" column="ATRIB_ID" select="getAtributos"/>
>
>and atrib_id is not an ArrayList<Atrib>
>
>Now I have as property atrib_ which is an ArrayList<Atrib> and it gets the
>Attributes with the function getAtributos. But there is no column for this
>.
>
><result property="atrib_" column="????" select="getAtributos" />
>
>If I put as column ATRIB_ID (which is not an ArrayList<Atrib>), then I
>obtain the error
>
>Error setting property 'setAtrib_' ... Cause:
>java.lang.IllegalArgumentException: argument type mismatch
>
>Any idea? Thanks
>
>
>
>
>
>
>
>>From: "Jeff Butler" <je...@gmail.com>
>>Reply-To: user-java@ibatis.apache.org
>>To: user-java@ibatis.apache.org
>>Subject: Re: select doubt
>>Date: Thu, 19 Jul 2007 10:08:58 -0500
>>
>>I belive the issue is that your setter isn't quite right. Should be like
>>this:
>>
>>public void setAtrib_ (ArrayList<Atrib> atrib_) {this.atrib_ = atrib_;}
>>
>>If you do it this way, iBATIS will know to expect multiple values for the
>>attributes.
>>
>>Jeff Butler
>>
>>
>>
>>
>>On 7/19/07, Francisco Exposito Aguilera <fc...@hotmail.com> 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
>>>
>>>
>>>
>>>
>
>_________________________________________________________________
>Un amor, una aventura, compañía para un viaje. Regístrate gratis en MSN
>Amor & Amistad. http://match.msn.es/match/mt.cfm?pg=channel&tcid=162349
>
_________________________________________________________________
Un amor, una aventura, compañía para un viaje. Regístrate gratis en MSN Amor
& Amistad. http://match.msn.es/match/mt.cfm?pg=channel&tcid=162349
Re: select doubt
Posted by Francisco Exposito Aguilera <fc...@hotmail.com>.
I´ve checked my code and I think I am doing something wrong in my resultMap,
but I don´t know how to solve it...
<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>
In my old resultMap I had
<result property="atrib_id" column="ATRIB_ID" select="getAtributos"/>
and atrib_id is not an ArrayList<Atrib>
Now I have as property atrib_ which is an ArrayList<Atrib> and it gets the
Attributes with the function getAtributos. But there is no column for this .
<result property="atrib_" column="????" select="getAtributos" />
If I put as column ATRIB_ID (which is not an ArrayList<Atrib>), then I
obtain the error
Error setting property 'setAtrib_' ... Cause:
java.lang.IllegalArgumentException: argument type mismatch
Any idea? Thanks
>From: "Jeff Butler" <je...@gmail.com>
>Reply-To: user-java@ibatis.apache.org
>To: user-java@ibatis.apache.org
>Subject: Re: select doubt
>Date: Thu, 19 Jul 2007 10:08:58 -0500
>
>I belive the issue is that your setter isn't quite right. Should be like
>this:
>
>public void setAtrib_ (ArrayList<Atrib> atrib_) {this.atrib_ = atrib_;}
>
>If you do it this way, iBATIS will know to expect multiple values for the
>attributes.
>
>Jeff Butler
>
>
>
>
>On 7/19/07, Francisco Exposito Aguilera <fc...@hotmail.com> 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
>>
>>
>>
>>
_________________________________________________________________
Un amor, una aventura, compañía para un viaje. Regístrate gratis en MSN Amor
& Amistad. http://match.msn.es/match/mt.cfm?pg=channel&tcid=162349
Re: select doubt
Posted by Jeff Butler <je...@gmail.com>.
I belive the issue is that your setter isn't quite right. Should be like
this:
public void setAtrib_ (ArrayList<Atrib> atrib_) {this.atrib_ = atrib_;}
If you do it this way, iBATIS will know to expect multiple values for the
attributes.
Jeff Butler
On 7/19/07, Francisco Exposito Aguilera <fc...@hotmail.com> 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
>
>
>
>