How to reference EJBs from another EJB in Oracle Workshop for WebLogic?

2.7k Views Asked by At

I need a help of how-to-do-it in the Weblogic development environment (Oracle Workshop for WebLogic 10.3).

I have a session bean in one .jar, and I need to use it from a message driven bean in another .jar. I want to use the "java:comp/env/..." notation when looking up the session bean.

jndiCtx = new InitialContext();
workerHome = (WorkerSBLocalHome) jndiCtx.lookup("java:comp/env/ejb/WorkerSBLocalHome");
WorkerSBLocal worker = workerHome.create();

Thus I need to create the ejb reference in the MDB component deployment descriptor (ejb-jar.xml):

<ejb-local-ref>
    <ejb-ref-name>ejb/WorkerSBLocalHome</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local-home>test.WorkerSBLocalHome</local-home>
    <local>test.WorkerSBLocal</local>
    <ejb-link>WorkerEJB.jar#WorkerSB</ejb-link>
</ejb-local-ref>

This works (tested). The problem is, that the MDB deployment descriptor is generated, and each time I edit the MDB source, the Oracle Workshop re-generates the deployment descriptor using the class annotations, and overwrites my additions.

So my question is: What is the best way of referencing an EJB from a MDB when working with the Oracle Workshop for WL? Or, is there any other prefered way of creating the bean references when using the ejb annotations than the one I outlined above? Or should I place my bean reference somewhere else?

1

There are 1 best solutions below

0
On

It seems that there is no way to edit the generated deployment descriptor manually (if you do not want to loose your changes). But, you still can specify its content using the annotations.

@EjbLocalRef(name="ejb/WorkerSBLocalHome", type=Constants.RefType.SESSION, 
    home="test.WorkerSBLocalHome", local="test.WorkerSBLocal",
    link="WorkerEJB.jar#WorkerSB")
@MessageDriven(ejbName = "HelloWorldMDB", 
    destinationJndiName="jms.RequestQueue", destinationType = "javax.jms.Queue")
public class Test extends GenericMessageDrivenBean implements
    MessageDrivenBean, MessageListener {
    .....
    jndiCtx = new InitialContext();
    workerHome = (WorkerSBLocalHome) jndiCtx.lookup("java:comp/env/ejb/WorkerSBLocalHome");
    WorkerSBLocal worker = workerHome.create();
    .....
}

This approach still forces you to specify concrete jndi names in the code, but you can always modify the generated deployment descriptor content at the deployment time.