Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is primary key a must for an entity bean

 
NareshAnkuskani Kumar
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it mandatory to configure a primarykey in the deployment descriptor.

Not all the tables in the database contains a primarykey.

Suppose i have created an entity bean which represents a table that do not have a primary key.

Now my question is what can i put as a return type of 'ejbCreate' method in the above created entity bean & how do i configure the primarykey information in DeploymentDescriptor?
 
Elton Kuzniewski
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why you have a table without pk?!
[ March 11, 2008: Message edited by: Elton Kuzniewski ]
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't sure, but why you don't need primary key?

How you find an entity without its identity? Or you don't want to find?
 
NareshAnkuskani Kumar
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

let me put the query in simple words.

Using entity beans is it possible to update or insert or delete a row in a database table which doesn't have a primary key?
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think it's possible. Which object will you be updating? What would be the differentiator for the object that you are updating to that of the other objects in the table?
 
Uchana Jackson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you referring to 2.x or 3.0 spec? EJB3 supports 2.x entity beans.

for JPA, refer to section 2.1.4 of the JSR220 persistence spec.

you must have a PK for an entity class in JPA.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by NareshAnkuskani Kumar:
Thanks for your reply.

let me put the query in simple words.

Using entity beans is it possible to update or insert or delete a row in a database table which doesn't have a primary key?


A table doesn't need to have a primary key, but in most cases a table should have one. If we don't have a primary key, how can we identify data in the table? That's not good.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Bean Provider must specify the primary key class for an
entity bean with bean-managed persistence, and may (but is not required to) specify the primary key class for an entity bean with container-managed persistence.

For a CMP bean, the PK can be inferred from the findByPrimaryKey method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic