aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes where to generate the primary keys for EntityBeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "where to generate the primary keys for EntityBeans" Watch "where to generate the primary keys for EntityBeans" New topic
Author

where to generate the primary keys for EntityBeans

Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
A basic design question.
Say i have a Customer Entity object.
There is a corresposnding Customer value object which will be used by the UI layer for display.
Now when i create a customer thro' the jsp,
i will be creating a Customer value object and then send it across to the server layer to save it.
Where is the primary key for the Entiy bean generated?
on the UI layer / server layer?
What is the general practice.
if it is on the server layer, i will end up creating a Customer value object which does'nt have an id. is that ok?
In all other cases of modify / update, the UI layer will obviously have an id to deal with upfront.
Somebody in our team says that is a practice to generate keys on UI??
something am not aware of but please comment
thanx!
Laudney Ren
Ranch Hand

Joined: Jan 06, 2002
Posts: 111
a Value Object doesn't need a primary id. If you want to insert one line to the table in database, place the codes in the corresponding EJB ejbCreate(...) function.


" Veni, vidi, vici "<br />" I came, I saw, I conquered "
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
I agree ... and if you're looking for ideas and algorithms to generate primary keys, take a look at Floyd Marinescu's book on EJB Design Patterns.
Mon Mayor
Ranch Hand

Joined: Mar 07, 2002
Posts: 40
If you are using a Value Object for display purpose I assume that it is a read only object created by the Customer bean. So the client has to specifically create it initially. If you are talking of an updatable Value Object even then the creation of the bean is where the primary key will have to be created. Hope this helps.
Chana Campos
Greenhorn

Joined: Jun 09, 2002
Posts: 19
HI
You should also be aware that primary keys can be generated automatically by WLS by using the appropriate tags in your Deployment Descriptor.
Since a PK is something only your database should be aware of - and if you're using CMP, then the container would create the PK at the time of initial insertion of the row in the db. The primary key can be a sequence number generated by your database - you decide when you're doing your design which works better for you.
Cheers,
Chana
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: where to generate the primary keys for EntityBeans
 
Similar Threads
Tomcat 5 _ Mysql 5
find & Select
Common DAO layer Code Base - Hibernate Mapping XML changes
database access pattern
implementation strategy for a simple ordering application.