ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brandon Goodin" <brandon.goo...@gmail.com>
Subject Re: Re-Post:: Same Connection Guaranteed during a Transaction?
Date Mon, 31 Jul 2006 03:57:53 GMT
iBATIS 1.x source code is still available for you to explore. iBATIS 1.x is
no longer supported. You will likely not get any assistance with this issue.

Brandon

On 7/30/06, Fred Janon <fjanon@yahoo.com> wrote:
>
> Sorry for the repost, but I am atill looking for an answer to my
> question. Basically I need to do an INSERT and get the ID (PK) of the
> insert in mySQL. MySQL has the "last_insert_id()" function to do that
> but it has to be executed in the same connection as the INSERT,
> otherwise it returns 0. I have 2 mapped statements in my XML maps, one
> to do the insert and one to do the last_insert_id(). I need to find a
> way to execute them in the same connection. I tried to include the 2
> stements in a transaction but they are still executed in 2 connections.
>
> Thanks,
>
> Fred
>
> --- Fred Janon <fjanon@yahoo.com> wrote:
>
> > I am trying to get the last_insert_id() in mySQL after an insert. I
> > read
> > in a forum that during a transaction, the same connection was
> > guaranteed
> > to be used for the duration of the transaction. That's not my
> > experience
> > using Spring and iBatis 1.3.1. Using the code below, I get 2
> > different
> > connection ids. I am a bit lost with the concept of a transaction if
> > the
> > connection is not maintained.
> >
> > Any comments?
> >
> > Thanks
> >
> > Fred
> >
> > getSqlMap().startTransaction();
> > connectionId =
> >
> (Integer)getSqlMapTemplate().executeQueryForObject("ConnectionId",null);
> > System.out.println("iBatisTasks createTask connectionId: " +
> > connectionId);
> >
> > getSqlMapTemplate().executeUpdate("createTask", task);
> >
> > Integer taskId = new Integer(0);
> > taskId =
> >
> (Integer)getSqlMapTemplate().executeQueryForObject("lastTaskId",null);
> > System.out.println(">>>>>>>>>> iBatisTasks createTask
id: " +
> > taskId);
> >
> > connectionId =
> >
> (Integer)getSqlMapTemplate().executeQueryForObject("ConnectionId",null);
> > System.out.println("iBatisTasks createTask connectionId: " +
> > connectionId);
> >
> > getSqlMap().commitTransaction();
> >
> > > begin:vcard
> > fn:fjanon
> > n:Janon;Fred
> > email;internet:fjanon@yahoo.com
> > title:Sr S/W Engineer & Architect
> > x-mozilla-html:TRUE
> > url:http://www.geocities.com/fjanon
> > version:2.1
> > end:vcard
> >
> >
>
>

Mime
View raw message