-
1. Re: EJB3 session bean with EJB2 session dependency
javasutra Aug 29, 2005 10:19 AM (in response to javasutra)This is from the EJB3 tutorial docs:
@EJB and @Resource also create an entry within the JNDI ENC of the bean. So, the above @EJB injection will create an entry for the reference calculator bean under "java:comp.ejb3/env/ejb/calculator". Note, the ENC name SHOULD be "java:/comp/env", but the JBoss Application server is currently being refactored in this area, so an EJB3 specific namespace is being used.
I think this is my problem. Is there any way to force the ENC name for the injection to be in java:/comp/env? -
2. Re: EJB3 session bean with EJB2 session dependency
sandello Dec 8, 2005 1:08 AM (in response to javasutra)Did you solve your problem?
-
3. Re: EJB3 session bean with EJB2 session dependency
oglueck Mar 29, 2006 7:28 AM (in response to javasutra)I am trying to do the same but without any success.
I want to inject the EJB 2 business interface into an EJB 3 MDB. So I write:@EJB(name="ejb/Esb") EsbAdapter adapter;
In the ejb-jar.xml I declare:<message-driven> <ejb-name>OutflowMdb</ejb-name> .... <ejb-ref> <ejb-ref-name>ejb/Esb</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>com.vendor.EsbAdapterHome</home> <remote>com.vendor.EsbAdapter</remote> </ejb-ref> </message-driven>
Finally the jboss.xml contains:<message-driven> <ejb-name>OutflowMdb</ejb-name> <ejb-ref> <ejb-ref-name>ejb/Esb</ejb-ref-name> <jndi-name>someVendor/EsbAdpater</jndi-name> </ejb-ref> </message-driven>
But I get For EJB OutflowMdb could not find jndi binding based on interface only for @EJB(com.vendor.EsbAdapter) not used by any EJBs
The same happens when I leave away the declaration in the ejb-jar.xml
I can't find any docs on how to correctly do this. -
4. Re: EJB3 session bean with EJB2 session dependency
oglueck Mar 29, 2006 11:54 AM (in response to javasutra)A step further:
It seems that the ejb-ref in ejb-jar.xml is not necessary (as expected) and this is equivalent to specifying a @EJB annotation.
Furthermore as the two EARs use separate class loaders we need this in the jboss.xml<ejb-ref> <ejb-ref-name>ejb/Esb</ejb-ref-name> <jndi-name>jnp://localhost:1100/someVendor/Adpater</jndi-name> </ejb-ref>
however now I get:
Unable to inject jndi dependency: env/ejb/Adapter into field protected com.vendor.EsbAdapterHome test.OutflowMdb.sifHome
with a reason:
javax.naming.NameNotFoundException: com.vendor.EsbAdapterHome not bound as a result of org.jnp.interfaces.NamingContext.resolveLink -
5. Re: EJB3 session bean with EJB2 session dependency
bdecoste Mar 29, 2006 5:58 PM (in response to javasutra)Here's an example of how to reference an EJB2.x bean from an EJB3.0 bean in two ways. The first is using annotations for the ejb reference and the other using the deployment descriptor.
The following is the EJB3 bean:@Stateless(name="Test3") @Remote(Test3.class) @RemoteBinding(jndiBinding="Test3") @EJBs({@EJB(name="injected/Test2", mappedName="Test2")}) public class Test3Bean implements Test3 { private static final Logger log = Logger.getLogger(Test3Bean.class); @EJB(name="ejb/Test2") private Test2Home test2Home=null; public void testAccess() throws Exception { Test2 test2 = test2Home.create(); try { InitialContext jndiContext = new InitialContext(); Test2Home home = (Test2Home)jndiContext.lookup(Container.ENC_CTX_NAME + "/env/injected/Test2"); test2 = home.create(); } catch (Exception e) { e.printStackTrace(); } } }
The following is the EJB2.x ejb-jar.xml:<ejb-jar> <enterprise-beans> <session> <ejb-name>ejb/Test2</ejb-name> <home>org.jboss.ejb3.test.reference21_30.Test2Home</home> <remote>org.jboss.ejb3.test.reference21_30.Test2</remote> <ejb-class>org.jboss.ejb3.test.reference21_30.Test2Bean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> </session> </enterprise-beans> </ejb-jar>
And the EJB2.x jboss.xml:<jboss> <enterprise-beans> <session> <ejb-name>ejb/Test2</ejb-name> <jndi-name>Test2</jndi-name> </session> </enterprise-beans> </jboss>
Now the EJB3 ejb-jar.xml<ejb-jar> <enterprise-beans> <session> <ejb-name>Test3</ejb-name> <ejb-ref> <ejb-ref-name>ejb/Test2</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> </ejb-ref> </session> </enterprise-beans> </ejb-jar>
And the EJB3 jboss.xml:<jboss> <enterprise-beans> <session> <ejb-name>Test3</ejb-name> <ejb-ref> <ejb-ref-name>ejb/Test2</ejb-ref-name> <jndi-name>Test2</jndi-name> </ejb-ref> </session> </enterprise-beans> </jboss>
-
6. Re: EJB3 session bean with EJB2 session dependency
oglueck Mar 30, 2006 3:27 AM (in response to javasutra)Thanks. This is exactly what I am doing. But my 2.x bean is in an isolated EAR. And that seems to be a problem. I have to use the deployment descriptor reference because I must not hard code the JNDI name. Any ideas?