One approach is to use bean managed persistence and implement the
ejbPostCreate method to retrieve the generated id into the instanciated
bean.

Its a slow approach but the only one you can get working, since the ejb spec
does not handle identity fields.

If you want to use identity fields and have control over the db-schema you
can use the Counter ejb from evermind or write your own identity generator
bean that generates new ints for tables. This is the approach you have to
use with containermanaged persistence...

Good luck.

Klaus Myrseth

-----Opprinnelig melding-----
Fra: Krista Richmond [mailto:[EMAIL PROTECTED]]
Sendt: 30. januar 2001 16:03
Til: Orion-Interest
Emne: RE: When using autonumber for the primarykey...


If it's actually an autonumber field (at least with SQL Server), just insert
the rest of the fields (not including the autonumbered field), e.g.
(presuming your table includes First_Name,Last_Name, and an
autonumber...say, a Customer_ID field): 

"INSERT INTO tblMyData(First_Name,Last_Name) VALUES('Sam','Adams')"

The table will automatically generate the autonumber for the ID field, hence
the name ;-).  Additionally, if you *try* to insert a value into the
autonumber field, SQL Server will generate an error.  I'm not sure whether
there may be different behaviors in different DBs...anyone?

HTH

-----Original Message-----
From: Øystein Walle [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 30, 2001 3:37 AM
To: Orion-Interest
Subject: When using autonumber for the primarykey...



I'm just wondering what to do when inserting into a table where the
primarykey has incremental int type? 
Is this possible?

Please help.

Walle



Reply via email to