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 Colin Williams <co...@gmail.com> on 2005/02/13 20:50:44 UTC

Indexing POJOs

Is there a way to index my POJOs without running another SQL statement
similar to the way it is done in Hibernate?
eg

All my POJOs have an object that acts as the key for the object, called id

currently I generate this in Ibatis by defining another SQL statement
to retrieve the id field

	
<resultMap id="getCustomerResult" class="customer">
	<result property="id" column="{account=ACCOUNT,branch=BRANCH}"
select="getCustomerId"/>
	<result property="email" column="email"/>
</resultMap>

but this also means that for every record I retrieve from the relevant
file i must run another SQL statement to generate the id.

Is there any way in Ibatis to do this without running another SQL Statement
eg in Hibernate
		<composite-id name="id" class="CustomerKey">
		  <key-property name="account" type="long" column="ACCOUNT"/>
		  <key-property name="branch" type="long" column="BRANCH"/>		  
		</composite-id>

will take the values from the fields ACCOUNT and BRANCH and use them
to construct a CustomerKey object

Re: Indexing POJOs

Posted by Colin Williams <co...@gmail.com>.
Kris,
thanks for that,
so in theory i should be able to say

<result property="id.account" column="ACCOUNT" />
<result property="id.branch" column="BRANCH" />

ill let you know if that works


On Sun, 13 Feb 2005 21:34:21 +0000 (GMT), Kris A. Jenkins
<kr...@yahoo.co.uk> wrote:
> --- Colin Williams <co...@gmail.com>
> wrote:
> > Is there a way to index my POJOs without running
> > another SQL statement
> > similar to the way it is done in Hibernate?
> > eg
> >
> > All my POJOs have an object that acts as the key for
> > the object, called id
> >
> > currently I generate this in Ibatis by defining
> > another SQL statement
> > to retrieve the id field
> >
> >
> > <resultMap id="getCustomerResult" class="customer">
> >       <result property="id"
> > column="{account=ACCOUNT,branch=BRANCH}"
> > select="getCustomerId"/>
> >       <result property="email" column="email"/>
> > </resultMap>
> >
> > but this also means that for every record I retrieve
> > from the relevant
> > file i must run another SQL statement to generate
> > the id.
> >
> > Is there any way in Ibatis to do this without
> > running another SQL Statement
> > eg in Hibernate
> >               <composite-id name="id" class="CustomerKey">
> >                 <key-property name="account" type="long"
> > column="ACCOUNT"/>
> >                 <key-property name="branch" type="long"
> > column="BRANCH"/>
> >               </composite-id>
> >
> > will take the values from the fields ACCOUNT and
> > BRANCH and use them
> > to construct a CustomerKey object
> 
> Colin,
> 
> Have you had a look in the developer's guide under the
> heading, "Avoiding N+1 Selects (1:1)"?  I think you
> can use the same recipe to solve your problem...
> 
> HTH,
> Kris
> 
> 
> ___________________________________________________________
> ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com
>

Re: Indexing POJOs

Posted by Kris Jenkins <kr...@yahoo.co.uk>.
Colin Williams wrote:

>Kris,
>
>I tried this and it does try to set the property on the id field, but
>of course it throws an error because it has used a default constructor
>so the id is of type Object.
>
>I need some way to indicate to Ibatis that I want to create my object
>with a composite key identifier object, say of type CustomerKey, for
>instance with the fields specified.
>
>Your suggestion is part 2, setting the properties of the key object,
>is there any solution for part 1.
>  
>
Colin,

I've just tried it over here without any problems.  Can we see the error 
(and maybe the code, too)?

Kris

-- 
Kris Jenkins
Email:  kris@jenkster.com
Blog:   http://cafe.jenkster.com/
Wiki:   http://wiki.jenkster.com/



Re: Indexing POJOs

Posted by Colin Williams <co...@gmail.com>.
Kris,

I tried this and it does try to set the property on the id field, but
of course it throws an error because it has used a default constructor
so the id is of type Object.

I need some way to indicate to Ibatis that I want to create my object
with a composite key identifier object, say of type CustomerKey, for
instance with the fields specified.

Your suggestion is part 2, setting the properties of the key object,
is there any solution for part 1.

cheers
Colin.W
http://as400blog.blogspot.com

Re: Indexing POJOs

Posted by "Kris A. Jenkins" <kr...@yahoo.co.uk>.
 --- Colin Williams <co...@gmail.com>
wrote: 
> Is there a way to index my POJOs without running
> another SQL statement
> similar to the way it is done in Hibernate?
> eg
> 
> All my POJOs have an object that acts as the key for
> the object, called id
> 
> currently I generate this in Ibatis by defining
> another SQL statement
> to retrieve the id field
> 
> 	
> <resultMap id="getCustomerResult" class="customer">
> 	<result property="id"
> column="{account=ACCOUNT,branch=BRANCH}"
> select="getCustomerId"/>
> 	<result property="email" column="email"/>
> </resultMap>
> 
> but this also means that for every record I retrieve
> from the relevant
> file i must run another SQL statement to generate
> the id.
> 
> Is there any way in Ibatis to do this without
> running another SQL Statement
> eg in Hibernate
> 		<composite-id name="id" class="CustomerKey">
> 		  <key-property name="account" type="long"
> column="ACCOUNT"/>
> 		  <key-property name="branch" type="long"
> column="BRANCH"/>		  
> 		</composite-id>
> 
> will take the values from the fields ACCOUNT and
> BRANCH and use them
> to construct a CustomerKey object

Colin,

Have you had a look in the developer's guide under the
heading, "Avoiding N+1 Selects (1:1)"?  I think you
can use the same recipe to solve your problem...

HTH,
Kris



	
	
		
___________________________________________________________ 
ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com