I have mapped the primary key for a CMP EJB to a primary key column in the DB2 database. This column is an IDENTITY column (autoincrement). How do I create a new row using the bean. I cant have a create method to which I pass the value of the primary column field as this value will be generated by the database.
Thanks
Discussions
EJB programming & troubleshooting: Help - Primary Key column is auto increment in the database
-
Help - Primary Key column is auto increment in the database (2 messages)
- Posted by: Aniesh Chawla
- Posted on: February 16 2001 07:15 EST
Threaded Messages (2)
- Help - Primary Key column is auto increment in the database by Somil Nanda on February 19 2001 00:23 EST
- Help - Primary Key column is auto increment in the database by Aniesh Chawla on February 20 2001 01:36 EST
-
Help - Primary Key column is auto increment in the database[ Go to top ]
- Posted by: Somil Nanda
- Posted on: February 19 2001 00:23 EST
- in response to Aniesh Chawla
This is how we r doing it.
make another table with only one column that will contain a number which will be incremented everytime it is being called(do this using a stored procedure or something)
now just before calling the create method on ur entity bean , run a sql querry which will return the value strored in the new table, use this as ur PK of the entity bean.
The usefullness of doing it like this depends on ur arch. too. we need to call this create method from only one place and that too not very often.
There might be other ways to do it, but in our project this method is working out fine.
-
Help - Primary Key column is auto increment in the database[ Go to top ]
- Posted by: Aniesh Chawla
- Posted on: February 20 2001 01:36 EST
- in response to Somil Nanda
Thanks Somil. I am now doing roughly the same thing you suggested. I am using a Singleton in combination with a table to generate the keys.