ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject Re: select with iterate
Date Sun, 24 Apr 2005 00:42:40 GMT
I believe your code would incorrectly generate the following sql
statements (all on one line):

select * from content where id = 1
select * from content where id = 2
select * from content where id = 3
...

Take a look at the these test cases:

http://tinyurl.com/dadn5
http://svn.apache.org/repos/asf/incubator/ibatis/trunk/java/mapper/mapper2/test/com/ibatis/sqlmap/maps/DynamicAccount.xml

You probably want to do something like this:

 SELECT * FROM content WHERE id IN
 <iterate property="idList" open="(" close=")"  conjunction=",">
  #idList[]#
 </iterate>

That would generate this sql:

SELECT * FROM content WHERE id IN (1,2,3)

If you want three seperate queries, your dao class would need to make
three seperate calls to the database.

--- Jason Punzalan <jasonpunzalan@gmail.com> wrote:
> Can someone show me an example of doing a select with iterate? Is it 
> possible to do the following....
> 
> <statement id="getAllByList" resultClass="Content"
> parameterClass="Content" 
> resultMap="content-result" >
> <dynamic> 
> <iterate property="idList">
> select * from content where
> id = #idList[]#
> </iterate>
> </dynamic>
> </statement>
> 
> I'm currently getting an java.sql.SQLException...running mysql.
> 
> Thanks
> 

Mime
View raw message