users@glassfish.java.net

Re: Set up InitialContext for JNDI lookup under Windows Vista

From: <glassfish_at_javadesktop.org>
Date: Tue, 06 Jan 2009 11:58:04 PST

Hi,

I was visiting your blog. You say,

ejb-jar.xml

<ejb-jar>
    <description>Sample test</description>
    <display-name>Sample test </display-name>
  <enterprise-beans>
      <session>
          <description> Sample bean </description>
          <display-name> Sample bean </display-name>
          <ejb-name>SampleRemote</ejb-name>
          <home>examples.SampleRemoteHome</home>
          <remote>examples.SampleRemote</remote>
          <ejb-class>examples.SampleEjb</ejb-class>
          <session-type>Stateless</session-type>
          <transaction-type>Bean</transaction-type>
      </session>
  </enterprise-beans>
</ejb-jar>

 sun-ejb-jar.xml

<sun-ejb-jar>
        <enterprise-beans>
                <ejb>
                        <ejb-name>SampleRemote</ejb-name>
                        <jndi-name>SampleRemote</jndi-name>
                </ejb>
        </enterprise-beans>
</sun-ejb-jar>
 

web.xml

<web-app>
    <distributable/>
    <servlet>
        <servlet-name>SampleTestServlet</servlet-name>
        <display-name>Sample Test Servlet</display-name>
        <servlet-class>servlets.SampleTestServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>SampleTestServlet</servlet-name>
        <url-pattern>/SampleTestServlet</url-pattern>
    </servlet-mapping>
</web-app>

that is my case. I do it your way and it does work. I cannot lookup the Home interfaces.

These are my descriptors,

ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<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">
  <enterprise-beans>
        <entity>
              <ejb-name>AccountHome</ejb-name>
              <local-home>com.sun.ebank.ejb.account.AccountHome</local-home>
              <local>com.sun.ebank.ejb.account.Account</local>
              <ejb-class>com.sun.ebank.ejb.account.AccountBean</ejb-class>
              <persistence-type>Bean</persistence-type>
              <prim-key-class>java.lang.String</prim-key-class>
              <reentrant>false</reentrant>
              <resource-ref>
                    <description>Conexion BD</description>
                    <res-ref-name>jdbc/glassfishmysqlpool</res-ref-name>
                    <res-type>javax.sql.DataSource</res-type>
                    <res-auth>Container</res-auth>
            <res-sharing-scope>Shareable</res-sharing-scope>
                </resource-ref>
    </entity>
    <entity>
              <ejb-name>CustomerHome</ejb-name>
              <local-home>com.sun.ebank.ejb.customer.CustomerHome</local-home>
              <local>com.sun.ebank.ejb.customer.Customer</local>
              <ejb-class>com.sun.ebank.ejb.customer.CustomerBean</ejb-class>
              <persistence-type>Bean</persistence-type>
              <prim-key-class>java.lang.String</prim-key-class>
              <reentrant>false</reentrant>
              <resource-ref>
                    <description>Conexion BD</description>
                    <res-ref-name>jdbc/glassfishmysqlpool</res-ref-name>
                    <res-type>javax.sql.DataSource</res-type>
                    <res-auth>Container</res-auth>
            <res-sharing-scope>Shareable</res-sharing-scope>
            </resource-ref>
    </entity>
    <entity>
      <ejb-name>TxHome</ejb-name>
      <local-home>com.sun.ebank.ejb.tx.TxHome</local-home>
      <local>com.sun.ebank.ejb.tx.Tx</local>
      <ejb-class>com.sun.ebank.ejb.tx.TxBean</ejb-class>
      <persistence-type>Bean</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      <reentrant>false</reentrant>
              <resource-ref>
                    <description>Conexion BD</description>
                    <res-ref-name>jdbc/glassfishmysqlpool</res-ref-name>
                    <res-type>javax.sql.DataSource</res-type>
                    <res-auth>Container</res-auth>
            <res-sharing-scope>Shareable</res-sharing-scope>
            </resource-ref>
    </entity>
    <session>
      <ejb-name>AccountControllerHome</ejb-name>
      <home>com.sun.ebank.ejb.account.AccountControllerHome</home>
      <remote>com.sun.ebank.ejb.account.AccountController</remote>
      <ejb-class>com.sun.ebank.ejb.account.AccountControllerBean</ejb-class>
      <session-type>Stateful</session-type>
      <transaction-type>Bean</transaction-type>
      <ejb-local-ref>
          <ejb-ref-name>AccountHome</ejb-ref-name>
          <ejb-ref-type>Entity</ejb-ref-type>
          <local-home>com.sun.ebank.ejb.account.AccountHome</local-home>
          <local>com.sun.ebank.ejb.account.Account</local>
      </ejb-local-ref>
    </session>
    <session>
      <ejb-name>CustomerControllerHome</ejb-name>
      <home>com.sun.ebank.ejb.customer.CustomerControllerHome</home>
      <remote>com.sun.ebank.ejb.customer.CustomerController</remote>
      <ejb-class>com.sun.ebank.ejb.customer.CustomerControllerBean</ejb-class>
      <session-type>Stateful</session-type>
      <transaction-type>Bean</transaction-type>
      <ejb-local-ref>
          <ejb-ref-name>CustomerHome</ejb-ref-name>
          <ejb-ref-type>Entity</ejb-ref-type>
          <local-home>com.sun.ebank.ejb.customer.CustomerHome</local-home>
          <local>com.sun.ebank.ejb.customer.Customer</local>
      </ejb-local-ref>
    </session>
    <session>
      <ejb-name>TxControllerHome</ejb-name>
      <home>com.sun.ebank.ejb.tx.TxControllerHome</home>
      <remote>com.sun.ebank.ejb.tx.TxController</remote>
      <ejb-class>com.sun.ebank.ejb.tx.TxControllerBean</ejb-class>
      <session-type>Stateful</session-type>
      <transaction-type>Bean</transaction-type>
      <ejb-local-ref>
          <ejb-ref-name>AccountHome</ejb-ref-name>
          <ejb-ref-type>Entity</ejb-ref-type>
          <local-home>com.sun.ebank.ejb.account.AccountHome</local-home>
          <local>com.sun.ebank.ejb.account.Account</local>
      </ejb-local-ref>
      <ejb-local-ref>
          <ejb-ref-name>TxHome</ejb-ref-name>
          <ejb-ref-type>Entity</ejb-ref-type>
          <local-home>com.sun.ebank.ejb.tx.TxHome</local-home>
          <local>com.sun.ebank.ejb.tx.Tx</local>
      </ejb-local-ref>
    </session>
    </enterprise-beans>
    <assembly-descriptor>
     <container-transaction>
         <method>
            <ejb-name>AccountHome</ejb-name>
            <method-name>getCreditLine</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountHome</ejb-name>
            <method-name>findByCustomerId</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountHome</ejb-name>
            <method-name>findByPrimaryKey</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountHome</ejb-name>
            <method-name>create</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountHome</ejb-name>
            <method-name>getDetails</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountHome</ejb-name>
            <method-name>getBalance</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountHome</ejb-name>
            <method-name>getType</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountHome</ejb-name>
            <method-name>setType</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountHome</ejb-name>
            <method-name>setDescription</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountHome</ejb-name>
            <method-name>setBalance</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountHome</ejb-name>
            <method-name>setCreditLine</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountHome</ejb-name>
            <method-name>setBeginBalance</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountHome</ejb-name>
            <method-name>setBeginBalanceTimeStamp</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>remove</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>findByLastName</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>findByPrimaryKey</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>create</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>findByAccountId</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>getDetails</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>setLastName</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>setFirstName</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>setMiddleInitial</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>setStreet</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>setCity</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>setState</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>setZip</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>setPhone</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerHome</ejb-name>
            <method-name>setEmail</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
           <container-transaction>
         <method>
            <ejb-name>TxHome</ejb-name>
            <method-name>remove</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>TxHome</ejb-name>
            <method-name>findByAccountId</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>TxHome</ejb-name>
            <method-name>findByPrimaryKey</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>TxHome</ejb-name>
            <method-name>create</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>TxHome</ejb-name>
            <method-name>getDetails</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
   </assembly-descriptor>
</ejb-jar>


sun-ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
<sun-ejb-jar>
  <enterprise-beans>
    <ejb>
        <ejb-name>AccountHome</ejb-name>
        <jndi-name>AccountHome</jndi-name>
    </ejb>
    <ejb>
        <ejb-name>CustomerHome</ejb-name>
        <jndi-name>CustomerHome</jndi-name>
    </ejb>
    <ejb>
        <ejb-name>TxHome</ejb-name>
        <jndi-name>TxHome</jndi-name>
    </ejb>
    <ejb>
      <ejb-name>AccountControllerHome</ejb-name>
      <jndi-name>AccountControlerHome</jndi-name>
      <ejb-ref>
              <ejb-ref-name>AccountHome</ejb-ref-name>
              <jndi-name>AccountHome</jndi-name>
      </ejb-ref>
    </ejb>
    <ejb>
      <ejb-name>CustomerControllerHome</ejb-name>
      <jndi-name>CustomerControllerHome</jndi-name>
      <ejb-ref>
        <ejb-ref-name>CustomerHome</ejb-ref-name>
        <jndi-name>CustomerHome</jndi-name>
      </ejb-ref>
    </ejb>
    <ejb>
      <ejb-name>TxControllerHome</ejb-name>
      <jndi-name>TxControllerHome</jndi-name>
      <ejb-ref>
              <ejb-ref-name>TxHome</ejb-ref-name>
              <jndi-name>TxHome</jndi-name>
      </ejb-ref>
      <ejb-ref>
              <ejb-ref-name>AccountHome</ejb-ref-name>
              <jndi-name>AccountHome</jndi-name>
      </ejb-ref>
    </ejb>
  </enterprise-beans>
</sun-ejb-jar>

As you can see, I have three session bean that call to its respective entity bean. But I am declaring wrongly the EJBs because the lookup method gives me a NamingException.

Any idea about what is happening?

Best regards,
Jose Alvarez de Lara
[Message sent by forum member 'josealvarezdelara' (josealvarezdelara)]

http://forums.java.net/jive/thread.jspa?messageID=324359