Hi danch, this is an excellent description, that should make it into the JBoss docs! regards Georg ___ ___ | + | |__ Georg Rehfeld Woltmanstr. 12 20097 Hamburg |_|_\ |___ [EMAIL PROTECTED] +49 (40) 23 53 27 10 ----- Original Message ----- From: "danch" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, June 11, 2001 9:26 AM Subject: Re: [JBoss-user] Re: Primary Key Error? (was Re: OutOfMemoryError) > Nicolai P Guba wrote: > > > Simple question (I hope): > > > > If I'd like to use CMP for a project. mySQL supports auto-generating > > the primary key for an inserted row (AUTO_INCREMENT). Is this feature > > supported by jboss? > > > > If not, what strategy would you recommend for handling primary keys > > (never done it any other way but to rely upon the database to generate > > the value). > > Ah! I think I may have tried answering this, but had problems with > outbound mail from work. > > auto_increment is not supported by JBoss at this time - there are way > too many different syntaxes, and in some databases it isn't possible for > the container to get the key value back, which is a Bad Thing. > > I would reccommend that you use a database sequence facility, if > available (I'm not a mySQL user). You can lookup your datasource and > make your call to get the key value just as you would in a BMP bean > (don't do the insert!, just get the key value and assign it to your key > field and return it) > > You might want to take a further step and put the call to the sequence > into a stateless session bean's method and mark that method as > RequiresNew transaction. This way you'll release any locks on the > sequence quickly (though you might have unused numbers in your PK - if > that's a problem you're probably doing something unwise) > > If mySQL doesn't have standalone sequences, you can construct a table > with a key-name column and a key-value column, then get the values out > of that by calling another bean with RequiresNew transactions. The > RequiresNew is very important here if you expect to require any > conncurrent inserts. > > -danch _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
