File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Can primary key have primitive values? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Can primary key have primitive values?" Watch "Can primary key have primitive values?" New topic

Can primary key have primitive values?

Puneet Vashisht
Ranch Hand

Joined: Jul 30, 2005
Posts: 44
Hi guyz

With CMP enitity beans we have to assign a primary key. Now i can definitely store primitive values in the fields. Like i may have a field count and declare it int type. So question is that can i also make count as my primary key. Does it alwayz have to be a class, cant i use primitive values in it.

Micheal Jacob
Ranch Hand

Joined: Nov 25, 2002
Posts: 89

PK cannot be primitive type.
Anyway you can use wrapper classes.

Ranch Hand

Joined: Aug 18, 2005
Posts: 372
you cannot return null from the ejbCreate() of a CMP bean if its return type is int, can you?
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3322
For container-managed persistence, a primary key class must meet the following requirements:

* The access control modifier of the class is public.
* All fields are declared as public.
* The fields are a subset of the bean's persistent fields.
* The class has a public default constructor.
* The class implements the hashCode() and equals(Object other) methods.
* The class is serializable.

Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam Study Guide and Quiz
Exam 1Z0-810: Upgrade to Java SE 8 Programmer Study Guide and Quiz
I agree. Here's the link:
subject: Can primary key have primitive values?
It's not a secret anymore!