users@glassfish.java.net

Re: Change from JEE 5 to earlier J2EE 1.4 in a web app with an EJB jar

From: <glassfish_at_javadesktop.org>
Date: Mon, 29 Dec 2008 07:29:43 PST

Hi,

I have changed the descriptors ejb-jar.xml and sun-ejb-jar.xml as follow,

#1.- 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>AccountBean</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>CustomerBean</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>TxBean</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>AccountControllerBean</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>
    </session>
    <session>
      <ejb-name>CustomerControllerBean</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>
    </session>
    <session>
      <ejb-name>TxControllerBean</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>
    </session>
    </enterprise-beans>
    <assembly-descriptor>
     <container-transaction>
         <method>
            <ejb-name>AccountBean</ejb-name>
            <method-name>getCreditLine</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountBean</ejb-name>
            <method-name>findByCustomerId</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountBean</ejb-name>
            <method-name>findByPrimaryKey</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountBean</ejb-name>
            <method-name>create</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountBean</ejb-name>
            <method-name>getDetails</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountBean</ejb-name>
            <method-name>getBalance</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountBean</ejb-name>
            <method-name>getType</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountBean</ejb-name>
            <method-name>setType</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountBean</ejb-name>
            <method-name>setDescription</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountBean</ejb-name>
            <method-name>setBalance</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountBean</ejb-name>
            <method-name>setCreditLine</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountBean</ejb-name>
            <method-name>setBeginBalance</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>AccountBean</ejb-name>
            <method-name>setBeginBalanceTimeStamp</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>remove</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>findByLastName</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>findByPrimaryKey</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>create</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>findByAccountId</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>getDetails</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>setLastName</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>setFirstName</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>setMiddleInitial</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>setStreet</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>setCity</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>setState</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>setZip</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>setPhone</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>CustomerBean</ejb-name>
            <method-name>setEmail</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
           <container-transaction>
         <method>
            <ejb-name>TxBean</ejb-name>
            <method-name>remove</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>TxBean</ejb-name>
            <method-name>findByAccountId</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>TxBean</ejb-name>
            <method-name>findByPrimaryKey</method-name>
         </method>
         <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>TxBean</ejb-name>
            <method-name>create</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>
         <method>
            <ejb-name>TxBean</ejb-name>
            <method-name>getDetails</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
   </assembly-descriptor>
</ejb-jar>

#2.- 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>AccountControllerBean</ejb-name>
      <jndi-name>AccountControlerHome</jndi-name>
      <ejb-ref>
              <ejb-ref-name>AccountBean</ejb-ref-name>
              <jndi-name>AccountHome</jndi-name>
      </ejb-ref>
    </ejb>
    <ejb>
      <ejb-name>CustomerControllerBean</ejb-name>
      <jndi-name>CustomerControllerBean</jndi-name>
      <ejb-ref>
        <ejb-ref-name>CustomerBean</ejb-ref-name>
        <jndi-name>CustomerHome</jndi-name>
      </ejb-ref>
    </ejb>
    <ejb>
      <ejb-name>TxControllerBean</ejb-name>
      <jndi-name>TxControllerBean</jndi-name>
      <ejb-ref>
              <ejb-ref-name>TxBean</ejb-ref-name>
              <jndi-name>TxHome</jndi-name>
      </ejb-ref>
      <ejb-ref>
              <ejb-ref-name>AccountBean</ejb-ref-name>
              <jndi-name>AccountHome</jndi-name>
      </ejb-ref>
    </ejb>
  </enterprise-beans>
</sun-ejb-jar>

Please, what am i doing wrong to no get the JNDI namings for my EJB's?
The classes to get the home interfaces are,

package com.sun.ebank.util;
/**
 * This interface defines names in code used as args for lookup().
 */
public interface CodedNames {
    public static final String BANK_DATABASE = "java:comp/env/jdbc/glassfishmysqlpool";
    public static final String ACCOUNT_EJBHOME = "java:comp/env/ejb/AccountHome";
    public static final String ACCOUNT_CONTROLLER_EJBHOME =
        "java:comp/env/ejb/AccountControllerHome";
    public static final String CUSTOMER_EJBHOME = "java:comp/env/ejb/CustomerHome";
    public static final String CUSTOMER_CONTROLLER_EJBHOME =
        "java:comp/env/ejb/CustomerControllerHome";
    public static final String TX_EJBHOME = "java:comp/env/ejb/TxHome";
    public static final String TX_CONTROLLER_EJBHOME =
        "java:comp/env/ejb/TxControllerHome";
}

that defines the JNDI, and

package com.sun.ebank.util;

import javax.rmi.PortableRemoteObject;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import com.sun.ebank.ejb.account.AccountHome;
import com.sun.ebank.ejb.account.AccountControllerHome;
import com.sun.ebank.ejb.customer.CustomerHome;
import com.sun.ebank.ejb.customer.CustomerControllerHome;
import com.sun.ebank.ejb.tx.TxHome;
import com.sun.ebank.ejb.tx.TxControllerHome;
/**
 * This helper class fetches EJB home references.
 */
public final class EJBGetter {
    public static AccountHome getAccountHome() throws NamingException {
        InitialContext initial = new InitialContext();
        Object objref = initial.lookup(CodedNames.ACCOUNT_EJBHOME);

        return (AccountHome) PortableRemoteObject.narrow(objref,
            AccountHome.class);
    }

    public static AccountControllerHome getAccountControllerHome()
        throws NamingException {
        InitialContext initial = new InitialContext();
        Object objref = initial.lookup(CodedNames.ACCOUNT_CONTROLLER_EJBHOME);

        return (AccountControllerHome) PortableRemoteObject.narrow(objref,
            AccountControllerHome.class);
    }

    public static CustomerHome getCustomerHome() throws NamingException {
        InitialContext initial = new InitialContext();
        Object objref = initial.lookup(CodedNames.CUSTOMER_EJBHOME);

        return (CustomerHome) PortableRemoteObject.narrow(objref,
            CustomerHome.class);
    }

    public static CustomerControllerHome getCustomerControllerHome()
        throws NamingException {
        InitialContext initial = new InitialContext();
        Object objref = initial.lookup(CodedNames.CUSTOMER_CONTROLLER_EJBHOME);

        return (CustomerControllerHome) PortableRemoteObject.narrow(objref,
            CustomerControllerHome.class);
    }

    public static TxHome getTxHome() throws NamingException {
        InitialContext initial = new InitialContext();
        Object objref = initial.lookup(CodedNames.TX_EJBHOME);

        return (TxHome) PortableRemoteObject.narrow(objref, TxHome.class);
    }

    public static TxControllerHome getTxControllerHome()
        throws NamingException {
        InitialContext initial = new InitialContext();
        Object objref = initial.lookup(CodedNames.TX_CONTROLLER_EJBHOME);

        return (TxControllerHome) PortableRemoteObject.narrow(objref,
            TxControllerHome.class);
    }
}

to look up for those JNDI namings.

Help?

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

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