Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

public int ejbCreate() throws javax.ejb.CreateException

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Why is this ejbCreate method considered illegal in the CMP entity bean?

public int ejbCreate() throws javax.ejb.CreateException
{
...
}

extracted from Q.5 of HFEJB Pg. 363.

Thanks in advance!

Regards,
--Scott
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose it's because the primary key can't be "int" or any other primitive type, but I'm not sure about this. It should have been declarad "Integer" or any other wrapper type.
Can anyone confirm this or give us another reason?
Thanks.
 
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be Integer I think. Also by the end of ejbCreate() the primary key should be ready by taking as parameters from the ejbCreate() method. So no-arg create() or ejbCreate() consequently aint the ones for the entity beans.

Regards,
Leena
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Primary keys should be of type java.lang.Object (and of course RMI-IIOP compatible). The getPrimaryKey() methods in EntityContext and EJBObject interfaces return an object of type java.lang.Object. They do not return primitives. Also the <prim-key-class> tag in the deployment descriptor indicates that primary keys are objects.
[ February 12, 2005: Message edited by: Keerthi P ]
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The PK can't b a primitive type. U cn use the wrapper classes, instead. ie, you can use Integer as the PK class, but not int.
***********************************************
The PK must contain all info to find an entity within the persistent data store. To du this, it must :
String or Wrapper classes of primitives

Or

b any legal type in RMI/IIOP other than primitive data type. In other words, it must be serializable.

provide a hashcode() and equals() method.

***********************************************

thanx/binoj
 
Binoj Viswanathan
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
pls ignore my earlier msg.

The PK can't b a primitive type. U cn use the wrapper classes, instead. ie, you can use Integer as the PK class, but not int.
***********************************************
The PK must contain all info to find an entity within the persistent data store. To du this, it must :


(1) b any legal type in RMI/IIOP other than primitive data type. In other words, it must be serializable.
(2) provide proper implementation of hashcode() and equals() method.
(eg. String or Wrapper classes of primitives- by default they implement Srializable intf and override hashcode() and equals() methods of Object class)
for custom classes as PK(for compound PKs), u have 2 conform 2 abv two rules.


***********************************************

thanx/binoj
 
Scott H. Kao
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Thanks for your provided info!
I've got a better understanding of it now.

Regards,
--Scott
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic