wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Is primary key a must for an entity bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Is primary key a must for an entity bean" Watch "Is primary key a must for an entity bean" New topic
Author

Is primary key a must for an entity bean

NareshAnkuskani Kumar
Ranch Hand

Joined: Sep 15, 2005
Posts: 76
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

Joined: Dec 06, 2007
Posts: 44
Why you have a table without pk?!
[ March 11, 2008: Message edited by: Elton Kuzniewski ]

Elton Kuzniewski<br>SCJA 1.0, SCJP 5.0, SCWCD 5.0, SCBCD 5.0, SCJD (B&S - working on project),
<br><a href="http://www.eltonk.com.br/" target="_blank" rel="nofollow">www.eltonk.com.br</a>
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
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?


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
NareshAnkuskani Kumar
Ranch Hand

Joined: Sep 15, 2005
Posts: 76
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

Joined: Sep 26, 2006
Posts: 9345
    
    2

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?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Uchana Jackson
Ranch Hand

Joined: Dec 07, 2007
Posts: 37
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.


SCJP 1.4<br />SCBCD 5
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
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

Joined: Sep 29, 2002
Posts: 1683
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.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
 
wood burning stoves
 
subject: Is primary key a must for an entity bean
 
Similar Threads
PrimaryKey Class
Is it mandatory to configure a primarykey in the deployment descriptor.
RemoveException or RemoteException
Recommendation on design approach
what value to provide for prim-key-class in DD