Torque expects that the code will have supplied the pk's prior to the insert when using idMethod="none". If the db is generating the id, you should use autoincrement (i think that is most appropriate for an identity), or sequence, or native for the latest cvs.
"Pugh, Eric" wrote: > > I read/searched around, and it seems that when you do the insert in the save > method of the BasePeer, you should get an object back with the primary key. > However, I get a null, which I think is because my idMethod is none. > Therefore after the insert, Torque has no idea what the primary key was, > because it is an identity column. > > I ended up doing a custom executeQuery: Select max(product_id) from > products. However this does raise the issue that if two people do two > inserts at the same time, they might both get the same product id back! > > I will try the setNew. What does that actually do (other then tell torque > that its needs to do an insert)? Also, I think doing the copy causes the > setNew(true) to happen. > > Eric > > -----Original Message----- > From: Scott Eade [mailto:[EMAIL PROTECTED]] > Sent: Thursday, December 06, 2001 5:53 PM > To: Turbine Users List > Subject: Re: Copying and then saving a row into DB, how do I get the > primary key > > ----- Original Message ----- > From: "Pugh, Eric" <[EMAIL PROTECTED]> > > Hi all, > > > > I looked through the archives to find the answer, b/c I swear I saw the > > answer, but no luck... > > > > I am using MSSQL as my database, and all my tables are set with > > idMethod=none, using Turbine 2.1. > > > > I want to copy a product object with product id 2. So I do: > > productB = productA.copy(); > > Try adding this: > > productB.setNew(true); > > > productB.save(); > > > > This saves my new row in the database, but my productB's primary key is > > null. I used profiler and see the we are doing an insert, but there > doesn't > > be anything like return @@Identity or anything to pass back what my new > > primary key is. > > > > Is the only way of figuring what productB's primary key is to do a select > > max(product_id) on my products table? > > > > Eric > > HTH. > > Scott > > -- > 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]>
