• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB 2.0 CMP - How to autogenerate Pkey?  RSS feed

 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi-
I'm writing Entity beans using CMP 2.0 in WSAD 5.1.1 and DB2 v 8.1.
The PK is an indentity.
My problem: how to create an entity bean and let the container/db generate the PK. SQL will auto-generate just fine if the PK is not specified but not CMP. I've seen solutions where the key is calculated using SQL prior to the insert but I would like a more elegant solution.
thanks
Max
[ September 02, 2004: Message edited by: Max Tomlinson ]
 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way you should handle this depends both on your application server and your database.
I've worked with generated (actually, auto_increment) pk field with mysql and jboss, so i can only help you in this enviroment.
Probably, others can give you better information.
 
Benson Fung
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an example for you. You can take a look.


* @jboss.unknown-pk
* class = "java.lang.Integer"
* column-name = "CUST_NUM"
* jdbc-type = "INTEGER"
* sql-type = "SERIAL"
* auto-increment = "true"
* @jboss.entity-command name="postgresql-fetch-seq"
* class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCPostgreSQLCreateCommand"
* @jboss.entity-command-attribute name="sequence" value="custseq"
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!