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 lali m <m....@gmail.com> on 2008/08/25 02:43:20 UTC
Ibatis : multiple insert
hi,
I have to do multiple insert in same time and for the moment I not found how
do it.
exemple : for one student I have to do insert all books
Student student {
Sring name
.................
List<Book> bookList;
}
(studentTable ) 1---------------------- n(bookTable)
whene I insert a student I need to insert (0 or n) books
I need to do some things like that :
<insert id="InsertSudent" parameterClass="AnnonceDaoLine" >
insert into students (id, name,date, ..... ) values (?,?,?,....)
<selectKey resultClass="int" keyProperty="id" type="post">
SELECT @@IDENTITY AS id_student
</selectKey>
</insert>
<insert id="insertBooks" parameterClass="BookInfoLines">
insert into books (id, tilte, ......)
<iterate property="bookList" >
values (#id#, #tilte#, ....)
</iterate>
where id=#id_student#
</insert>
Re: Ibatis : multiple insert
Posted by Ian Zabel <ia...@ezabel.com>.
I think you need to iterate over the bookList in your Java code and
call your insert multiple times. Take the <iterate> out of the insert.
Maybe this will help you:
http://www.mail-archive.com/user-java@ibatis.apache.org/msg04760.html
Also, what's with the WHERE clause in your INSERT statement? I'm not
familiar with that syntax.
Ian.
On Aug 24, 2008, at 8:43 PM, lali m wrote:
> hi,
>
> I have to do multiple insert in same time and for the moment I not
> found how do it.
> exemple : for one student I have to do insert all books
>
> Student student {
> Sring name
> .................
>
>
> List<Book> bookList;
>
> }
>
> (studentTable ) 1---------------------- n(bookTable)
>
> whene I insert a student I need to insert (0 or n) books
> I need to do some things like that :
>
> <
>
> insert id="InsertSudent" parameterClass="AnnonceDaoLine" >
> insert into students (id, name,date, ..... ) values (?,?,?,....)
>
>
> <selectKey resultClass="int" keyProperty="id" type="post">
> SELECT @@IDENTITY AS id_student
>
>
> </selectKey>
>
> </insert>
>
> <insert id="insertBooks" parameterClass="BookInfoLines">
> insert into books (id, tilte, ......)
>
>
> <iterate property="bookList" >
> values (#id#, #tilte#, ....)
>
>
> </iterate>
> where id=#id_student#
>
>
> </insert>
>
Re: Ibatis : multiple insert
Posted by averm <td...@gmail.com>.
I am having a similar situation.
did u happen to find a way to get this working.
lali m wrote:
>
> hi,
>
> I have to do multiple insert in same time and for the moment I not found
> how
> do it.
> exemple : for one student I have to do insert all books
>
> Student student {
> Sring name
> .................
>
>
> List<Book> bookList;
>
> }
>
> (studentTable ) 1---------------------- n(bookTable)
>
> whene I insert a student I need to insert (0 or n) books
> I need to do some things like that :
>
>
> <insert id="InsertSudent" parameterClass="AnnonceDaoLine" >
>
> insert into students (id, name,date, ..... ) values (?,?,?,....)
>
> <selectKey resultClass="int" keyProperty="id" type="post">
>
> SELECT @@IDENTITY AS id_student
>
> </selectKey>
>
> </insert>
>
> <insert id="insertBooks" parameterClass="BookInfoLines">
>
> insert into books (id, tilte, ......)
>
> <iterate property="bookList" >
>
> values (#id#, #tilte#, ....)
>
> </iterate>
>
> where id=#id_student#
>
> </insert>
>
>
--
View this message in context: http://www.nabble.com/Ibatis-%3A-multiple-insert-tp19136408p19464373.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.