JBoss Community

Re: How to use ejb3 in ejb2 using xdoclet

created by bharath sadanagiri in EJB3 - View the full discussion

I got the solution for this problem
I have choosen the last option, that is using the Xdoclet generated configuaration files.
The following steps that I have followed
1. I did changes on top of the XMLs that got generated using Xdoclets
2. Create a LocalHome in ejb3.0 eventhough it is not required(For ejb3 LocalHome is junk file but it is useful when called from ejb2)
3. In ejb-jar.xml under <message-driven > element declared the ejb3.0 like below

<ejb-local-ref >
      <ejb-ref-name>ejb/AuditService</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      <local-home>com.receiver.audit.AuditServiceLocalHome</local-home>
      <local>com.receiver.audit.AuditServiceLocal</local>
</ejb-local-ref>

4. In jboss.xml under <message-driven> element declared the ejb3.0 like below

<ejb-local-ref >
  <ejb-ref-name>ejb/AuditService</ejb-ref-name>
  <local-jndi-name>AuditService/localHome</local-jndi-name>
</ejb-local-ref >

5. In MDB(In my case I need the AuditService in MDB) look up the ejb like following and use
      auditServiceLocalHome = (AuditServiceLocalHome)ctx.lookup("java:comp/env/ejb/AuditService");
      auditServiceLocal = (AuditServiceLocal)auditServiceLocalHome.create();
6. Changed the build file to include in EAR the above XML files instead of the files that got generated using Xdoclets
7. For the verification purpose go to jmx-console (jboss:service=JNDIView) and check AuditService is visible in java:comp as well as in Global JNDI Namespace

java:comp namespace of the ReceiverMDB bean:
   +- env (class: org.jnp.interfaces.NamingContext)
   |   +- ejb (class: org.jnp.interfaces.NamingContext)
   |   |   +- AuditService[link -> AuditService/localHome] (class: javax.naming.LinkRef)
  
  
Global JNDI Namespace
  +- HTTPConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
  +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
  +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
  +- AuditService (class: org.jnp.interfaces.NamingContext)
  |   +- localHome (proxy: $Proxy80 implements interface com.receiver.audit.AuditServiceLocalHome)

Thanks,

Bharath

Reply to this message by going to Community

Start a new discussion in EJB3 at Community