• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ejbCreate return type..

 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can it be a primitive? does it have to be an Object?
 
John Ip
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure which bean type you are talking about. But I guess you are talking entity bean. The return type for the ejbCreate() method of the entity bean had to be the same as the primary key type. You had to specified the class of the type you chose in the DD with the <primkey-class> element. So only wrapper class or java.lang.String can be the return type.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andres Gonzalez:
can it be a primitive? does it have to be an Object?

Yes, for entity beans....java.lang.Object or its subclass.
For all other types of beans, it is void.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
While we are here on this, I would like to point one thing that could be worth keeping in mind.
I am using SUN ONE appserver and I realized that in my Bean Impl it doesn't matter to the code if I return null or the actual key object for the EntityBean's ejbCreate(), that just got inserted into the DB. This is because my Abstract EntityBean class gets subclassed by Container specific class which takes care of returning proper object from corresponding create() method...
So to the end user writing the code sometimes it might sound confusing when the code returns correct Object even if his/her ejbCreate() returns null...
Regards,
Maulin
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
interesting, thanks!
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maulin Vasavada:
While we are here on this, I would like to point one thing that could be worth keeping in mind.
I am using SUN ONE appserver and I realized that in my Bean Impl it doesn't matter to the code if I return null or the actual key object for the EntityBean's ejbCreate(), that just got inserted into the DB. This is because my Abstract EntityBean class gets subclassed by Container specific class which takes care of returning proper object from corresponding create() method...
So to the end user writing the code sometimes it might sound confusing when the code returns correct Object even if his/her ejbCreate() returns null...

Great Maulin!
I wanted to try this out for some time. In fact, the only CMP2.0 entity bean sample in Ed Roman's book returns the primary key Object and not null!
in the ejbCreate() method. (ejb1.1/2.0/2.1 specs dictate null to be returned).
I found the foll. from EJB1.1 spec, p:131, sec 9.4.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.
Note: The above requirement is to allow the creation of an entity bean with bean-managed persistence by subclassing an entity bean with container-managed persistence. The Java language rules for overriding methods in subclasses requires the signatures of the ejbCreate(...) methods in the subclass and the superclass be the same.

So it doesn't really matter to the Container, whether the return value is null or the primary key Object.
[ March 16, 2004: Message edited by: Vish Kumar ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic