The mm mysql jdbc driver has a last_insert_id() method to call after an insert. It's the only way the driver returns you that info. What I don't know though is how "accurate" it is? I think you can shoot yourself in the foot if the call to it is not properly encapsulated within a thread-safe/synchronized context. I'd hate for a call to last_insert_id() to return a different id (someone else's insert that just so happened between my insert and the call to last_insert_id()).
Therefore I think encapsulating this within a sync method and having an action invoke it (like someone else on this group mentioned) may be the way to go on this. thanks, Theron Struts Newsgroup To: [EMAIL PROTECTED] <struts@baseb cc: eans.com> Subject: Re: Hi Folks, 2 questions about Actions and their instance 04/01/02 10:40 AM Please respond to Struts Users Mailing List Subject: Re: Hi Folks, 2 questions about Actions and their instance From: Vic Cekvenich <[EMAIL PROTECTED]> === Imeditely calling is not good enough. You must use a JDBC driver specific call that returns the last "affected rows" ID. This gives you the new PK. Vic [EMAIL PROTECTED] wrote: >>>There are 2 different path elements but both refer to the same Action >>> > class > >>>instance... Does this mean 2 static instances of >>>BillingActionPreloadForm will exist or will only just 1 exist between >>> > the 2 > >>>different action mappings that link to the same class? >>> > >>I don't know, but it doesn't matter. You should always assume that >>any specific instance of an Action class could potentially serve multiple >>threads at once. Or else what's the point of putting your app on the >>web? ;-) >> > > Reason I brought this up is that I plan to use mysql. Mysql has those > AUTO INCREMENT fields and I want to insert a record and immediately call > last_index_id() to get the newly inserted row. If I do this is just one > and only one action, I may be able to prevent a timing/race condition by > which last_index_id() may accidentally be returned from the wrong insert. > I definitely want to prevent that from happening. > > thanks, > Theron > > > > > Jim Crossley > <jcrossley@if To: Struts Users Mailing List > leet.com> <[EMAIL PROTECTED]> > cc: > 04/01/02 Subject: Re: Hi Folks, 2 questions about Actions and their > 09:02 AM instance > Please > respond to > Struts Users > Mailing List > > > > > > [EMAIL PROTECTED] writes: > > [...] > > >>So here's my 2 question(s): >> >>1. I then assume that "perform()" is synchronized >> > > No. If all data objects are local to the perform method, there's no > reason for it to be synchronized. If the data objects referred to in > perform are shared, then their access should probably be synchronized, > but not necessarily. > > >>2. What about those cases where 2 different action mappings resort to >> > the > >>same action class? >> > > [...] > > >>There are 2 different path elements but both refer to the same Action >> > class > >>instance... Does this mean 2 static instances of >>BillingActionPreloadForm will exist or will only just 1 exist between the >> > 2 > >>different action mappings that link to the same class? >> > > I don't know, but it doesn't matter. You should always assume that > any specific instance of an Action class could potentially serve multiple > threads at once. Or else what's the point of putting your app on the > web? ;-) > > -- Jim > > -- > To unsubscribe, e-mail: < > mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: < > mailto:[EMAIL PROTECTED]> > > > > > -- > To unsubscribe, e-mail: < mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: < mailto:[EMAIL PROTECTED]> > -- To unsubscribe, e-mail: < mailto:[EMAIL PROTECTED]> For additional commands, e-mail: < mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>