aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes ejbCreate, primary keys and deployment descriptors question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "ejbCreate, primary keys and deployment descriptors question" Watch "ejbCreate, primary keys and deployment descriptors question" New topic
Author

ejbCreate, primary keys and deployment descriptors question

Jason Mowat
Ranch Hand

Joined: Aug 17, 2003
Posts: 79
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 ]
alzamabar
Ranch Hand

Joined: Jul 24, 2002
Posts: 379
We use Oracle Sequences to auto-generate numeric keys. However, it seems to me that JBoss is implementing (or it has already implemented) a component to auto-generate keys. But this would be a question to post to JBoss forum. For the exam, you are supposed to have that key value before actually the container writes a record to the underlying persistent storage, and how you get it, actually, it's up to you.

HTH,

Marco


Marco Tedone<br />SCJP1.4,SCJP5,SCBCD,SCWCD
Jason Mowat
Ranch Hand

Joined: Aug 17, 2003
Posts: 79
Greets,

I am finding some interesting discussions online regarding my question. One thread that is answering many of my questions can be found here.

Cheers,
Jason
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ejbCreate, primary keys and deployment descriptors question