• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

If Pkey of EB is of primitive type then what's the return type of ejbCreate()

 
Bhanu
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not mentioned any where in spec about what's going to be the return type of ejbCreate() if the Primary Key is primitive type.

And what's going to be mentioned for prim-key-class in the DD?

Spec has mentioned that EB can have persistent field type primitive and never said about the primary key.

Thanx.
 
MI Mohammed
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the spec.
14.1.9.1 Primary key that maps to a single field in the entity bean class
The Bean Provider uses the primkey-field element of the deployment descriptor to specify the
container-managed field of the entity bean class that contains the primary key. The field�s type must be
the primary key type.

The container uses the abstract setter and getter method to determine the primary key type. The return type for CMT and BMT ejbCreate()is always the primary key but for CMT, you should always return null (ie in the return statement).The container is able to figure it out.
From the spec 14.1.2:
The ejbCreate(...) methods must be defined to return the primary key class type. The implementation of the ejbCreate(...) methods should be coded to return a null. The returned value is ignored by the Container.


Hope it helps
 
Sub swamy
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this (14.1.9.1) mean

we can declare int as a primary key ?
And DD would have <primkey-field>int</primkey-field> element in it ?

If so, what would the value of <prim-key-class> be ?
 
Bhanu
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spec has no direct mention on Primary Key Field Type. But we can infer from other explanation that primkey-class value must always be a Java Class. If your Primary key field is not a compound key and is basically a primitive type then you are supposed to wrap that in Wrapper class.
ejbCreate method should always be implemented to return Primary Key Class type. And in that case you should not define prim-key-field in DD. Hope this would clear your doubt.

It's very unfortunate that HFEJB has not discussed about such things in it.
[ March 07, 2006: Message edited by: Bhanu P Jasthi ]
 
Kenny Lomax
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
p.333 HFEJB: "Primary Keys must be serializable."
I think in this sense primitives are not serializable as they do not extend serializable interface and therefore are not allowed as PKs.
Kenny
 
Bhanu
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Primitive type data is serializable. Isn't it?
That would have made a better sense, if it was mentioned as

PKey should be a serializable non-primitive Type.
 
Nishant Verma
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bhanu !! U nailed this one.
 
Sajid Moinuddin
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, What's the conclusion? I can't use a long/int/double as my pk? I have to use Long/Integer/Double??
 
Balaji Anand
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you have to use primitive type keys then we have to use a wrapper.
primitives are serializable but they are not classes.
Primary keys must be serializable classes.
hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic