Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where to generate the primary keys for EntityBeans

 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic