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:[EMAIL PROTECTED] 
Sent: Thursday, July 19, 2007 7:00 AM
To: [email protected]
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 <[EMAIL PROTECTED]>
>Reply-To: [email protected]
>To: [email protected]
>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" <[EMAIL PROTECTED]>
>>>Reply-To: [email protected]
>>>To: [email protected]
>>>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" <[EMAIL PROTECTED]>
>>>>Reply-To: [email protected]
>>>>To: <[email protected]>
>>>>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:[EMAIL PROTECTED]
>>>>Sent: woensdag 18 juli 2007 22:29
>>>>To: [email protected]
>>>>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" <[EMAIL PROTECTED]>
>>>> >Reply-To: [email protected]
>>>> >To: <[email protected]>
>>>> >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:[EMAIL PROTECTED]
>>>> >Sent: woensdag 18 juli 2007 17:42
>>>> >To: [email protected]
>>>> >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 '[EMAIL PROTECTED]'.  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/

Reply via email to