The primary key (or field or property of a composite primary key) should be one of the following types: - any Java primitive type; - any primitive wrapper type; - java.lang.String; - java.util.Date; - java.sql.Date.
In general, however, approximate numeric types (e.g., floating point types) should never be used in primary keys. Entities whose primary keys use types other than these will not be portable.
If generated primary keys are used, only integral types will be portable. If java.util.Date is used as a primary key field or property, the temporal type should be specified as DATE.
SCJP5 | SCBCD5 | SCEA5 Part 1
posted 12 years ago
Hi, Can we use primitive int / long for primary key? If no, please explain why we cant use it?
getPrimarykey() returns Object in EJB 2.0 so it makes it kind of hard to use a primitive as a primary key. I suggest that you wrap int using java.lang.Integer [ October 07, 2007: Message edited by: Kevin DesLauriers ]