IMOHO, it is better to stay away from allowing the DB to generate it's own, unique keys the peers just seem to be happier that way ;-) It appears that there is a lot of pain suffering associated with DB-specific key generation, more than I would want to deal with anyway.
I have went as a far as modifying the IDBroker class to generate database-wide unique keys (as opposed just table-wide unique keys) so my peer objects end up having unique identifiers unto themselves, i.e. object Foo and object Bar will, theoretically, never have id collisions (props out to jvz for educating me on the best way to implement this). Take a look at this link, (I think this is also a resource off of the Turbine homepage somewhere) http://www.ambysoft.com/mappingObjects.html about object relational mappings. It's a good read with lots of insight into object to relational db mapping and why it's a good idea to stay away from DB-specific key generation. My $0.02, Scott -----Original Message----- From: Pugh, Eric [mailto:[EMAIL PROTECTED]] Sent: Friday, December 07, 2001 7:51 AM To: 'Turbine Users List' Subject: RE: Copying and then saving a row into DB, how do I get the prima ry key 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]>
