Win a copy of Spring Boot in Practice this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Primary key - primitive

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why entity's bean primary key can't be primitive? Why should I wrap int into java.lang.Integer and return null in ejbCreate(...)? Isn't the container smart enough to see in DD that my primary key is simple int ?
I think every one of us has been thinking over the problem - entity's home create method returns Component interface - good; but what's this mess in ejbCreate methods in the entity bean's class ?
I have to see in EJB 2.1 if there is some change.
Regards
Toshe
 
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why entity's bean primary key can't be primitive?


javax.ejb.EJBObject and javax.ejb.EJBLocalObject both have a method 'getPrimaryKey' that returns an Object that you can cast to the type of your primary key. A primitive isn't an Object. You could also come up with a whole host of reasons why primitives would make life hell for the container vendor.

Why should I ... return null in ejbCreate(...)?


Remember that the spec has to cover both CMP (on exam) and BMP (not on exam) use of entity beans. BMP beans return the PK because the container has no other was of getting the primary key. CMP returns null because the container doesn't get the PK from the return result. The PK is constructed by the container via the attribute values you sent in ejbCreate() and reflection based on the prim-key-class and/or primkey-field content of the DD. Strictly speaking the Java code in a CMP bean may have no reason to be aware of the definition of its PK at all.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then would it be any problems if I DO return a PK object (not null) at the end of ejbCreate() of a CMP entity bean ??
[ February 04, 2004: Message edited by: Ken Ho ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic