Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Primary key in Entity Bean

 
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,
 
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
 
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
 
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 ]
 
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.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic