aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes can home business method return .... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "can home business method return ...." Watch "can home business method return ...." New topic
Author

can home business method return ....

Puneet Vashisht
Ranch Hand

Joined: Jul 30, 2005
Posts: 44
Hi,

HFEJB PgNo. 325 it sayz

"Client can call a home business method that returns a reference to bean's component interface".
My question is : "is it actually possible for a home business method to return a component interface?".

On PgNo.278 it contradicts the above written statement.

Thankz,
Puneet
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2854
    
  11

I don't have the book with me, but it seems that first statement is wrong. Business methods execute with the bean still in the pool, so there is no component interface. Page 180 of the EJB 2.0 spec shows that ejbHome methods can't access the EJBObject (or EJBLocalObject), so how could they return a reference to it?
Micheal Jacob
Ranch Hand

Joined: Nov 25, 2002
Posts: 89
Hi,

ejbSelect can return a remote/local component interface.
So why can't we call ejbSelect inside ejbHome method and return the same thing.

Micheal
Puneet Vashisht
Ranch Hand

Joined: Jul 30, 2005
Posts: 44
Hi,

You r very right Greg, because ejbHome methods can't access the EJBObject, there's no point of returning it.
According to HFEJB Pg No.278
"Home business methods can return something other than EJB object references! They are perfect for queries where the client just wants entity data, not references to themselves"
"They are also great for batch operations or anything else you might want to do with more than open specific entity, when you dont want to return references to the component inteface"

All these point justify that a home business method cannot return component interfaces.

But nothing stops from a select method to return component interfaces, and it is perfectly acceptable to call a select method from inside a home.

Secondly, HFEJB PG No. 325 sayz
"There are three ways to retrun a reference to the EJBObject":
1)Finder methods
2)Create methods from home.
3)Client calls a home business method that returns a reference to the bean's component interface.

I'm very confused...

Any help is well appreciated.

Thankz
Puneet
Micheal Jacob
Ranch Hand

Joined: Nov 25, 2002
Posts: 89
Hi,

I think, ejbHome methods CAN be used to return component interface.
But practically, bean provider may not use this method to return component interface. (Because he could very well define find method, which means less source code)

Regarding returning component interface, ejbHome method can return component interface, but until any method gets called in that EJBObject, container may not assign any entity object.

But still the bean which is used to execute ejbHome method is in pooled state. (i.e.) not attached to any entity.

Any help is much appreciated, to clear this out.

Micheal.
B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
My understanding is that you cannot do a context.getEJBObject() from a home business method. The bean executes the method from within the pool and is not tied to the EJBObject of any particular entity. But you can always do a JNDI look up, get the home interface of a bean, do a find by primary key, get the component interface reference and THEN return it to the caller, right?
Puneet Vashisht
Ranch Hand

Joined: Jul 30, 2005
Posts: 44
Hi,

i'm still very confused, because nothing stops me from calling a select method from a home business method, and wid select methods v can alwayz return component interfaces.

thankz,
Puneet
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2854
    
  11

OK, I read that page 278, and I believe all it's saying is that ejbSelect calls can return something besides the component interface or a collection of the component interfaces, not that it has to. An ejbSelect could also return a component interface or a collection of them, but then why not use a finder? Anyway, a home business method, in fact, could return a component interface, by calling an ejbSelect method. The bean would still be in the pool though, and in no way related to the remote interface(s) it was returning. The first time the client called a business method on that remote interface, the container would pull a bean out of the pool and call its ejbLoad method. It would be a strange coincidence if the bean instance pulled out of the pool was the same bean instance that executed the home business method.

B Satish's example is also correct. In fact, you can get the home interface from the ejbHome methods, so you could skip the JNDI lookup.

Great question, by the way. I think I've got everything straight in my mind now, but I'll be checking back to see if there are any corrections.
Puneet Vashisht
Ranch Hand

Joined: Jul 30, 2005
Posts: 44
thanks greg
 
wood burning stoves
 
subject: can home business method return ....