• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Primary key in Entity Bean

 
KRK Gowda
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Can a primary key for Entity bean be a primitive?
What are the possible datatypes that can be used for primary key for Entity?


Thanks and Regards,
 
Benoît de Chateauvieux
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi KRK Gowda,

In the EJB3 specification 2.1.4:

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.

Regards,

Beno�t
 
KRK Gowda
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can we use primitive int / long for primary key?
If no, please explain why we cant use it?

Thanks and Regards
 
Napu Sun
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for EJB 2, I think we cannot use primitives for primary key
 
Kevin DesLauriers
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Muralidhar Adhikarla
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think for EJB 3.0 , We can use primitive types as primary keys. So the answer for your question is Yes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic