One of the columns in the table is a primary key which
is auto generated by the MSSQL database using the
IDENTITY qualifier. I want some code snippet
to use the same feature in my Entity Bean and return
the primary key (using entityContext.getPrimaryKey()).
Which means I want to use primary key as the autogenerated
value in my entity bean and have that value returned
when i call entityContext.getPrimaryKey().
Has anybody tried this? Is this doable at all?
TIA.
sn
-
Use of sequence key in Entity beans (2 messages)
- Posted by: Narayanan S
- Posted on: July 07 2000 20:28 EDT
Threaded Messages (2)
- Use of sequence key in Entity beans by Ed Roman on July 08 2000 18:54 EDT
- Use of sequence key in Entity beans by alex black on July 12 2000 12:59 EDT
-
Use of sequence key in Entity beans[ Go to top ]
- Posted by: Ed Roman
- Posted on: July 08 2000 18:54 EDT
- in response to Narayanan S
CMP: I'm not sure how you'd do this. The application server queries your fields that you set up during ejbCreate() and uses those fields to populate the database.
BMP: You should be able to get away with it by asking the database to generate the ID during the SQL you write in ejbCreate(). -
Use of sequence key in Entity beans[ Go to top ]
- Posted by: alex black
- Posted on: July 12 2000 12:59 EDT
- in response to Narayanan S
I'm using CMP, and tried to do what you're suggesting, but had no luck.
If you used BMP, you could run the SQL "select @@identity" which is a mssql specific call to find the indenity of the last record inserted.
What I did was made a EJB entity bean called PrimaryKeyManager, and it has 1 field for each entity bean. For example it has a field called _productCurrentPrimaryKey, and a method like this:
int getNextProductPrimaryKey()
{
_productCurrentPrimaryKey++;
return _productCurrentPrimarykey;
}
- Alex