This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
ejbSelect can return a remote/local component interface. So why can't we call ejbSelect inside ejbHome method and return the same thing.
Joined: Jul 30, 2005
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.
Joined: Nov 25, 2002
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.
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?
Joined: Jul 30, 2005
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.
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.