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 Javier Leyba <xl...@gmail.com> on 2006/05/05 23:56:32 UTC

query inside a query

Hi

I've a sqlmap to a class that is filled with data from a select but
one field should be getted from another table and then I wonder if is
posible to make the second select in the same sqlmap file and return
data filled.

My sqlMap is

-----------
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-2.dtd">

<sqlMap namespace="Participes">
    <typeAlias alias="participes"
        type="org.jl.meriden.listados.dao.Participes" />

	<select id="selectParticipes"
	  resultClass="participes">
	<![CDATA[
		select
		E10CTA as nroCuenta,
		E10TSU as suscriptas,
		E10TRE as reembolsadas,
		E10TIT as saldoParticipe,
		E10TPG as saldoPignorado,
		E10PSU as saldoSuscripto,
		E10PRE as saldoRembolsado,
		E10PCM as saldoCosteMedio
		from dpicfic.E10PI
		where E01PI.E01FBA <> 0
    ]]>
	</select>		

</sqlMap>
------------

and I need to add another field that comes from another select that
receives E10CTA as parameter.


Thanks in advance


--
Javier Leyba
Barcelona - Spain
http://blog.leyba.com.ar

Re: query inside a query

Posted by Javier Leyba <xl...@gmail.com>.
Hi

I'm trying to do my best following the examples but I'm doing
something wrong because I couldn't see what I want.

I've this

<typeAlias alias="participes"
        type="org.jl.meriden.listados.dao.Participes" />

<resultMap id="resultParticipes" class="participes">
		<result property="nroCuenta" column="nroCuenta" />
		<result property="nombreParticipe" column="G09APE"
select="getNombreParticipe" />
		<result property="suscriptas" column="suscriptas" />
		<result property="rembolsadas"	column="rembolsadas" />
		<result property="saldoParticipe" column="saldoParticipe" />
		<result property="saldoPignorado" column="saldoPignorado" />
		<result property="saldoSuscripto" column="saldoSuscripto" />
		<result property="saldoRembolsado" column="saldoRembolsado" />
		<result property="saldoCosteMedio" column="saldoCosteMedio" />		
	</resultMap>


where nombreparticipe come from another select. Then I added the
corresponding select

<statement id="getNombreParticipe" parameterClass="java.lang.String"
resultMap="resultParticipes">
		<![CDATA[
		select G09CO.G09APE as nombreParticipe from G09CO where G09CO.G09COD = #value#
		]]>
	</statement>


When I run the program I can see all Participes properties except the
one that should come from the second select. As I didn't received an
error, I don't know if my mistake is passing parameter to second
select or retrieving data from it.

Could someone help me please ?

Thanks in advance

J

Re: query inside a query

Posted by Javier Leyba <xl...@gmail.com>.
Ohhh, I'm not too blind !!  :)

Thanks a lot !!!

J

On 5/6/06, Sven Boden <li...@pandora.be> wrote:
>  http://svn.apache.org/repos/asf/ibatis/trunk/java/docs/iBATIS-SqlMaps-2.pdf
>
> ;-)
>
> Javier Leyba wrote:
>
> > Thanks for all replys.
> >
> > Now I want to know where could I found a developers guide. I'm working
> > as blind as Stevie Wonder, just using my instinct and experience....
> > :)
> >
> > I couldn't seen a developers guide in ibatis home links !!
> >
> >
> > J
> >
> >
> >
> > On 5/6/06, Diran Ayandele <Ad...@sun.com> wrote:
> >
> >> Javier - you certainly can do this.  Look in the developer's guide under
> >> complex properties in result maps.  It's on page 25 in my printed copy.
> >>
> >> your result map for the main select will have a row like this:
> >>
> >> <result property="category" column="PRD_CAT_ID" select="getCategory"
> >>
> >> PRD_CAT_ID refers to the column from the first select you will use as
> >> the parameter for the second query.
> >> The select parameter refers to the statement name.
> >>
> >> Hope this is helpful!
> >> Diran
> >>
> >> Javier Leyba wrote:
> >>
> >> > Hi
> >> >
> >> > I've a sqlmap to a class that is filled with data from a select but
> >> > one field should be getted from another table and then I wonder if is
> >> > posible to make the second select in the same sqlmap file and return
> >> > data filled.
> >> >
> >> > My sqlMap is
> >> >
> >> > -----------
> >> > <?xml version="1.0" encoding="UTF-8" ?>
> >> > <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
> >> >    "http://www.ibatis.com/dtd/sql-map-2.dtd">
> >> >
> >> > <sqlMap namespace="Participes">
> >> >    <typeAlias alias="participes"
> >> >        type="org.jl.meriden.listados.dao.Participes" />
> >> >
> >> >     <select id="selectParticipes"
> >> >       resultClass="participes">
> >> >     <![CDATA[
> >> >         select
> >> >         E10CTA as nroCuenta,
> >> >         E10TSU as suscriptas,
> >> >         E10TRE as reembolsadas,
> >> >         E10TIT as saldoParticipe,
> >> >         E10TPG as saldoPignorado,
> >> >         E10PSU as saldoSuscripto,
> >> >         E10PRE as saldoRembolsado,
> >> >         E10PCM as saldoCosteMedio
> >> >         from dpicfic.E10PI
> >> >         where E01PI.E01FBA <> 0
> >> >    ]]>
> >> >     </select>
> >> >
> >> > </sqlMap>
> >> > ------------
> >> >
> >> > and I need to add another field that comes from another select that
> >> > receives E10CTA as parameter.
> >> >
> >> >
> >> > Thanks in advance
> >> >
> >> >
> >> > --
> >> > Javier Leyba
> >> > Barcelona - Spain
> >> > http://blog.leyba.com.ar
> >>
> >>
> >
> >
> > --
> > Javier Leyba
> > Barcelona - Spain
> > http://blog.leyba.com.ar
> >
> >
>
>


--
Javier Leyba
Barcelona - Spain
http://blog.leyba.com.ar

Re: query inside a query

Posted by Sven Boden <li...@pandora.be>.
 http://svn.apache.org/repos/asf/ibatis/trunk/java/docs/iBATIS-SqlMaps-2.pdf

;-)

Javier Leyba wrote:

> Thanks for all replys.
>
> Now I want to know where could I found a developers guide. I'm working
> as blind as Stevie Wonder, just using my instinct and experience....
> :)
>
> I couldn't seen a developers guide in ibatis home links !!
>
>
> J
>
>
>
> On 5/6/06, Diran Ayandele <Ad...@sun.com> wrote:
>
>> Javier - you certainly can do this.  Look in the developer's guide under
>> complex properties in result maps.  It's on page 25 in my printed copy.
>>
>> your result map for the main select will have a row like this:
>>
>> <result property="category" column="PRD_CAT_ID" select="getCategory"
>>
>> PRD_CAT_ID refers to the column from the first select you will use as
>> the parameter for the second query.
>> The select parameter refers to the statement name.
>>
>> Hope this is helpful!
>> Diran
>>
>> Javier Leyba wrote:
>>
>> > Hi
>> >
>> > I've a sqlmap to a class that is filled with data from a select but
>> > one field should be getted from another table and then I wonder if is
>> > posible to make the second select in the same sqlmap file and return
>> > data filled.
>> >
>> > My sqlMap is
>> >
>> > -----------
>> > <?xml version="1.0" encoding="UTF-8" ?>
>> > <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
>> >    "http://www.ibatis.com/dtd/sql-map-2.dtd">
>> >
>> > <sqlMap namespace="Participes">
>> >    <typeAlias alias="participes"
>> >        type="org.jl.meriden.listados.dao.Participes" />
>> >
>> >     <select id="selectParticipes"
>> >       resultClass="participes">
>> >     <![CDATA[
>> >         select
>> >         E10CTA as nroCuenta,
>> >         E10TSU as suscriptas,
>> >         E10TRE as reembolsadas,
>> >         E10TIT as saldoParticipe,
>> >         E10TPG as saldoPignorado,
>> >         E10PSU as saldoSuscripto,
>> >         E10PRE as saldoRembolsado,
>> >         E10PCM as saldoCosteMedio
>> >         from dpicfic.E10PI
>> >         where E01PI.E01FBA <> 0
>> >    ]]>
>> >     </select>
>> >
>> > </sqlMap>
>> > ------------
>> >
>> > and I need to add another field that comes from another select that
>> > receives E10CTA as parameter.
>> >
>> >
>> > Thanks in advance
>> >
>> >
>> > --
>> > Javier Leyba
>> > Barcelona - Spain
>> > http://blog.leyba.com.ar
>>
>>
>
>
> -- 
> Javier Leyba
> Barcelona - Spain
> http://blog.leyba.com.ar
>
>


Re: query inside a query

Posted by Javier Leyba <xl...@gmail.com>.
Thanks for all replys.

Now I want to know where could I found a developers guide. I'm working
as blind as Stevie Wonder, just using my instinct and experience....
:)

I couldn't seen a developers guide in ibatis home links !!


J



On 5/6/06, Diran Ayandele <Ad...@sun.com> wrote:
> Javier - you certainly can do this.  Look in the developer's guide under
> complex properties in result maps.  It's on page 25 in my printed copy.
>
> your result map for the main select will have a row like this:
>
> <result property="category" column="PRD_CAT_ID" select="getCategory"
>
> PRD_CAT_ID refers to the column from the first select you will use as
> the parameter for the second query.
> The select parameter refers to the statement name.
>
> Hope this is helpful!
> Diran
>
> Javier Leyba wrote:
>
> > Hi
> >
> > I've a sqlmap to a class that is filled with data from a select but
> > one field should be getted from another table and then I wonder if is
> > posible to make the second select in the same sqlmap file and return
> > data filled.
> >
> > My sqlMap is
> >
> > -----------
> > <?xml version="1.0" encoding="UTF-8" ?>
> > <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
> >    "http://www.ibatis.com/dtd/sql-map-2.dtd">
> >
> > <sqlMap namespace="Participes">
> >    <typeAlias alias="participes"
> >        type="org.jl.meriden.listados.dao.Participes" />
> >
> >     <select id="selectParticipes"
> >       resultClass="participes">
> >     <![CDATA[
> >         select
> >         E10CTA as nroCuenta,
> >         E10TSU as suscriptas,
> >         E10TRE as reembolsadas,
> >         E10TIT as saldoParticipe,
> >         E10TPG as saldoPignorado,
> >         E10PSU as saldoSuscripto,
> >         E10PRE as saldoRembolsado,
> >         E10PCM as saldoCosteMedio
> >         from dpicfic.E10PI
> >         where E01PI.E01FBA <> 0
> >    ]]>
> >     </select>
> >
> > </sqlMap>
> > ------------
> >
> > and I need to add another field that comes from another select that
> > receives E10CTA as parameter.
> >
> >
> > Thanks in advance
> >
> >
> > --
> > Javier Leyba
> > Barcelona - Spain
> > http://blog.leyba.com.ar
>
>


--
Javier Leyba
Barcelona - Spain
http://blog.leyba.com.ar

Re: query inside a query

Posted by Diran Ayandele <Ad...@Sun.COM>.
Javier - you certainly can do this.  Look in the developer's guide under 
complex properties in result maps.  It's on page 25 in my printed copy. 

your result map for the main select will have a row like this:

<result property="category" column="PRD_CAT_ID" select="getCategory"

PRD_CAT_ID refers to the column from the first select you will use as 
the parameter for the second query. 
The select parameter refers to the statement name.

Hope this is helpful!
Diran

Javier Leyba wrote:

> Hi
>
> I've a sqlmap to a class that is filled with data from a select but
> one field should be getted from another table and then I wonder if is
> posible to make the second select in the same sqlmap file and return
> data filled.
>
> My sqlMap is
>
> -----------
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
>    "http://www.ibatis.com/dtd/sql-map-2.dtd">
>
> <sqlMap namespace="Participes">
>    <typeAlias alias="participes"
>        type="org.jl.meriden.listados.dao.Participes" />
>
>     <select id="selectParticipes"
>       resultClass="participes">
>     <![CDATA[
>         select
>         E10CTA as nroCuenta,
>         E10TSU as suscriptas,
>         E10TRE as reembolsadas,
>         E10TIT as saldoParticipe,
>         E10TPG as saldoPignorado,
>         E10PSU as saldoSuscripto,
>         E10PRE as saldoRembolsado,
>         E10PCM as saldoCosteMedio
>         from dpicfic.E10PI
>         where E01PI.E01FBA <> 0
>    ]]>
>     </select>       
>
> </sqlMap>
> ------------
>
> and I need to add another field that comes from another select that
> receives E10CTA as parameter.
>
>
> Thanks in advance
>
>
> -- 
> Javier Leyba
> Barcelona - Spain
> http://blog.leyba.com.ar


Re: query inside a query

Posted by Diran Ayandele <Ad...@Sun.COM>.
You could also write an inner query joined on the E10CTA column whose 
syntax would depend on your database.

Javier Leyba wrote:

> Hi
>
> I've a sqlmap to a class that is filled with data from a select but
> one field should be getted from another table and then I wonder if is
> posible to make the second select in the same sqlmap file and return
> data filled.
>
> My sqlMap is
>
> -----------
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
>    "http://www.ibatis.com/dtd/sql-map-2.dtd">
>
> <sqlMap namespace="Participes">
>    <typeAlias alias="participes"
>        type="org.jl.meriden.listados.dao.Participes" />
>
>     <select id="selectParticipes"
>       resultClass="participes">
>     <![CDATA[
>         select
>         E10CTA as nroCuenta,
>         E10TSU as suscriptas,
>         E10TRE as reembolsadas,
>         E10TIT as saldoParticipe,
>         E10TPG as saldoPignorado,
>         E10PSU as saldoSuscripto,
>         E10PRE as saldoRembolsado,
>         E10PCM as saldoCosteMedio
>         from dpicfic.E10PI
>         where E01PI.E01FBA <> 0
>    ]]>
>     </select>       
>
> </sqlMap>
> ------------
>
> and I need to add another field that comes from another select that
> receives E10CTA as parameter.
>
>
> Thanks in advance
>
>
> -- 
> Javier Leyba
> Barcelona - Spain
> http://blog.leyba.com.ar