Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Primary key - primitive

 
Todor Mollov
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
  • 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.
 
Ken Ho
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic