my dog learned polymorphism*
The moose likes EJB and other Java EE Technologies and the fly likes How do DB-Auto-Generated Primary Key in EJB 2.0? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How do DB-Auto-Generated Primary Key in EJB 2.0?" Watch "How do DB-Auto-Generated Primary Key in EJB 2.0?" New topic
Author

How do DB-Auto-Generated Primary Key in EJB 2.0?

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
How do I make my bean a CMP bean, but have the ID field auto-generated by a database? Also, I have two other questions: 1. Why isn't this in the EJB 2.0 spec? 2. Other than using an auto-generated field, what would be another good way to do a primary key? Or a better way? Obviously, the people who did the spec must think they're not a good idea, because they didn't make it part of the spec (db-generated AND non-db-generated, ALL auto-generation of primary key is not included).
Sam Wang
Ranch Hand

Joined: Jul 17, 2001
Posts: 95
There's a good desc in ejb patterns at
theserverside.com


SCJP(2001)
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
No, their suggestion for a database-generated ID is for BMP beans only. I need something for my CMP bean. And their other solutions are not very good performance-wise, and not quite as safe and garaunteed to be unique. Using another bean to generate the ID's? That more DB calls! Ugh.
Why is this NOT a part of the EJB spec? What did they expect us to do for primary keys? Am I missing something? What else would people do? What's wrong with auto-generated IDs?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How do DB-Auto-Generated Primary Key in EJB 2.0?