• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bhanu !! U nailed this one.
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic