I'm working now on migration from EJB 2.0 to 3.0. Old session beans used xdoclets to configure some stuff.
I can understand almost all of them, but there is one thing that is bothering me.
Why do someone use @ejb.ejb-ref
in way like in code below.
/**
* @ejb:bean name="SomeBean"
* local-jndi-name="com/my/jndi/SomeBean"
* view-type="local" type="Stateless"
*
* @ejb.ejb-ref ejb-name="SomeBean"
* view-type="local"
*
* ..some more stuff here
*/
public class SomeBean implements SessionBean {
// class body here
}
There is few more @tags
in this xdoclet including some for configuring weblogic (@weblogic
).
Is there some reason we may want to add reference to bean itself? Second question, is this config still needed in ejb3?
I have this feeling that I read somewhere that this @weblogic
tags may sometimes need to use this kind of reference but I just cannot find it one more time. Is it true?
@EDIT
After talk with one of the authors of such classes, i find out that such self-reference may be used when one of bean methods calls second method (which may have to require new transaction) by using reference to instance of class it's owns.
After upgrade it can be replaced by something like this below.
@Stateless
public class SomeBean implements IBeanLocal {
@EJB
IBeanLocal someBean;
// class body here
}
My confusion was mainly caused by some unnecessary uses of this kind of self-reference. As pointed by Steve C, probably someone wasn't sure how to use this xdoclet feature.
First of all, the "local" view types imply that you're looking at EJB 2.1 code (not 2.0).
I agree that the @ejb.ejb-ref tag is curious. It would only be useful if it was using JNDI somewhere to look up another instance of the same type of session bean. And even then it's redundant because the ejb home objects are available in the bean's EJBContext object.
It's quite possible the original authors did not know what the ejb-ref was for. There was a lot of that going around at the time.
If there was an ejb-ref to another type of bean, then you would typically see a corresponding @weblogic.ejb-local-reference-description or @weblogic.ejb-reference-description which is used to generate the JNDI mapping information in the weblogic.xml file, linked by the ejb-name.
In any event, you would replace any of these lookup references with instance variables marked up with @EJB.
The complete xdoclet documentation (and source) is still available at (http://xdoclet.sourceforge.net/xdoclet/index.html), FWIW.