• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ejbCreate, primary keys and deployment descriptors question

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jason Mowat
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic