2 Replies Latest reply on Aug 19, 2011 1:07 PM by mitchelladam83

    JBoss 6.0.0.final Unable to lookup 2.1 Entity Bean local-home from java:comp/env

    mitchelladam83 Newbie

      Hi,

      Our app is currently migrating from 4.2.3 to 6 and I'm currently getting problems trying to lookup EJB 2.1 entity beans using the java:comp/env/ejb for any of the beans.

      configuration of them is as follows:

       

      --ejb-jar.xml

       

      <ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">

                <display-name>server-utils-ejbs</display-name>

                <enterprise-beans>

                          <entity>

                                    <ejb-name>Example</ejb-name>

                                    <local-home>com.test.util.timer.ExampleHome</local-home>

                                    <local>com.test.util.timer.Example</local>

                                    <ejb-class>com.test.util.timer.Example</ejb-class>

                                    <persistence-type>Container</persistence-type>

                                    <prim-key-class>java.lang.String</prim-key-class>

                                    <reentrant>false</reentrant>

                                    <abstract-schema-name>Example</abstract-schema-name>

                                    <cmp-field>

                                              <description>This is the PK</description>

                                              <field-name>key</field-name>

                                    </cmp-field>

                                    <cmp-field>

                                              <field-name>id</field-name>

                                    </cmp-field>

                                    <primkey-field>key</primkey-field>

                          </entity>

           </enterprise-beans>

      </ejb-jar>

       

      --jboss.xml

       

      <?xml version="1.0" encoding="UTF-8"?>

      <jboss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.jboss.com/xml/ns/javaee" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss_5_1.xsd" version="5.1">

                <security-domain>java:/jaas/server-login</security-domain>

      </jboss>

       

       

      JNDI tree shows that the entity is bound:

       

      java:comp namespace of the Example bean:

       

        +- TransactionSynchronizationRegistry[link -> java:TransactionSynchronizationRegistry] (class: javax.naming.LinkRef)
        +- env (class: org.jnp.interfaces.NamingContext)
        |   +- security (class: org.jnp.interfaces.NamingContext)
        |   |   +- subject[link -> java:/jaas/server-login/subject] (class: javax.naming.LinkRef)
        |   |   +- realmMapping[link -> java:/jaas/server-login/realmMapping] (class: javax.naming.LinkRef)
        |   |   +- security-domain[link -> java:/jaas/server-login] (class: javax.naming.LinkRef)
        |   |   +- authorizationMgr[link -> java:/jaas/server-login/authorizationMgr] (class: javax.naming.LinkRef)

       

      yet elsewhere in the application where I try to do:

       

      Class<H extends EJBLocalHome> homeClass = com.test.util.timer.ExampleHome.class;

       

      home = new InitialContext().lookup("java:comp/env/ejb/ExampleHome", homeClass);

       

      i get: {javax.naming.NameNotFoundException@41333}"javax.naming.NameNotFoundException: ExampleHome not bound"

       

      has the ENC binding changed between 4.2.3 and 6 so that these entries in the ejb-jar are not bound to the same locations?

       

      any help would be appreciated, thanks

       

      Adam

        • 1. Re: JBoss 6.0.0.final Unable to lookup 2.1 Entity Bean local-home from java:comp/env
          jaikiran pai Master

          The binding in java:comp/env will not be created until you have a ejb-ref or a ejb-local-ref configured in the ejb-jar.xml and jboss.xml. That's how the spec mandates it. I'm not sure how this was working in 4.2.x, since I would expect the java:comp/env lookup to fail there too. Are you sure you aren't missing some configurations?

          • 2. Re: JBoss 6.0.0.final Unable to lookup 2.1 Entity Bean local-home from java:comp/env
            mitchelladam83 Newbie

            hence the issue, the 5_0 and 5_1 schemas of jboss.xml don't support <entity> beans.

             

            I have managed to get around this by duplicating all the entities from the ejb-jar.xml to the jboss.xml and removing all dtd and schema reference (and therefore, validation) from the jboss.xml like so:

             

            <?xml version="1.0" encoding="UTF-8"?>

            <jboss>

              <security-domain>java:/jaas/server-login</security-domain>

                <enterprise-beans>

                    <entity>

                 <ejb-name>Example</ejb-name>

                 <jndi-name>ejb/local/ExampleHome</jndi-name>

                    </entity>

                </enterprise-beans>

            </jboss>

             

            but I simply shouldn't have to have this entry in there, it serves no purpose. Where this bean is referenced is unchanged. the configuration for the <ejb-ref> and <ejb-local-ref> was there all along. yet only by adding this superfluous entry does the jndi bind correctly to the java:comp/env for the associated bean.