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

public int ejbCreate() throws javax.ejb.CreateException

 
Scott H. Kao
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
 
Fernando Matias Valadao
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.
 
Leena Diwan
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
 
Keerthi P
Ranch Hand
Posts: 203
  • 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 ]
 
Binoj Viswanathan
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic