Greetings,
I have a question regarding the creation of primary keys for CMP beans in ejbCreate. A code example will probably illustrate my problem a little clearer, so I'll rely on that. I'm using xdoclet to set up the autogeneration of the key for
JBoss.
As you can see, I have declared an entity bean for JBoss with an autogenerating key for the category_id column; it's an arbitrary number that I don't really care about. However, the problem I foresee is that the bean itself does not know what this key is until AFTER it is inserted.
Page 333 of HFE has a Q&A about this situation and states that I HAVE to handle the generation of my key at all times with CMP beans.
Should I instead rely on fetching an autokey from the database from a sequence and set it explicitly in the bean AND the database table? Or put another way, should I never use autogenerating keys when creating a database table if I plan on using CMP on them? A consequence of this would be that all of my existing database tables that are currently set up with autogenerating key fields would need to be changed to accomodate CMP and it's primary key setting rules. Since these tables could be used by other non-EJB client, I obviously won't be doing that.
Can I set the primary key that was autogenerated in ejbCreate to the actual entity bean I am working with by fetching it in ejbPostCreate?
Is there a
pattern out there for using autogenerating keys in entity beans, or should I just not use that database feature and instead rely on fetching values from sequences?
Any assistance is appreciated!
Cheers,
Jason
[ July 31, 2004: Message edited by: Jason Mowat ]
[ July 31, 2004: Message edited by: Jason Mowat ]
[ July 31, 2004: Message edited by: Jason Mowat ]
[ July 31, 2004: Message edited by: Jason Mowat ]