2 Replies Latest reply on Apr 7, 2009 4:56 AM by Hans-Michael Rupp

    Adding EJB3 Stateless EJBs to an EJB2.1 jar ClassCastExcepti

    Hans-Michael Rupp Novice

      Hallo I am trying to add a Stateless Session Bean (EJB3 with annotations Stateless, Remote, Home ..) to an EJB 2.1 project on JBoss 4.2.3.
      The new SSB works well as I have tested with JUnit.
      However in the old code I get a ClassCastException at:

      SchnittstelleLocalHome lHome = (SchnittstelleLocalHome) ServiceLocator.lookupLocalHome( SchnittstelleLocalHome.JNDI_NAME );

      This is caused by adding an @Local Interface to a EJB3 Bean with an abritrary name. I have made sure that there a no Naming conflicts.
      Is this a known bug? Any workarounds?

        • 1. Re: Adding EJB3 Stateless EJBs to an EJB2.1 jar ClassCastExc
          jaikiran pai Master

          Could you please post the entire exception stacktrace and the relevant code from the EJB3 beans? Also please post any ejb-jar.xml or jboss.xml content that might be relevant. How is the application packaged? An EAR or a jar?

          • 2. Re: Adding EJB3 Stateless EJBs to an EJB2.1 jar ClassCastExc
            Hans-Michael Rupp Novice

            Thank you for your interest

            package de.dzbw.dnp.migvis.persistence;
            
            import de.dzbw.dnp.migvis.person.pojo.Bearbeitungverbund;
            
            public interface BearbeitungsverbundDAOI {
             public Bearbeitungverbund getBearbeitungverbund(int bvId);
            }
            
            
            package de.dzbw.dnp.migvis.persistence;
            
            import javax.ejb.Local;
            
            @Local
            public interface BearbeitungsverbundDAOLocal extends BearbeitungsverbundDAOI {
            
            }
            
            package de.dzbw.dnp.migvis.persistence;
            
            import javax.ejb.Remote;
            
            @Remote
            public interface BearbeitungsverbundDAORemote extends BearbeitungsverbundDAOI {
            
            }
            
            package de.dzbw.dnp.migvis.persistence;
            
            
            import java.sql.Connection;
            import java.sql.PreparedStatement;
            import java.sql.ResultSet;
            import java.sql.SQLException;
            import java.util.Date;
            
            import javax.ejb.Stateless;
            
            import org.apache.log4j.Logger;
            
            
            import de.dzbw.dnp.migvis.person.pojo.Bearbeitungverbund;
            import de.dzbw.dnp.migvis.person.pojo.Person;
            import de.dzbw.dnp.migvis.person.pojo.Personengruppenkennzeichen;
            import de.dzbw.dnp.migvis.person.pojo.Stellung;
            import de.dzbw.dnp.migvis.person.pojo.Vorgang;
            import de.dzbw.dnp.migvis.schnittstelle.common.BaseDAO;
            
            @Stateless
            public class BearbeitungsverbundDAO extends BaseDAO implements BearbeitungsverbundDAOLocal, BearbeitungsverbundDAORemote{
            
             private Logger log = Logger.getLogger(this.getClass());
            
             public Bearbeitungverbund getBearbeitungverbund(int bvId) {
             if (log.isDebugEnabled()) {
             log.debug("Entry getBearbeitungverbund(" + bvId + ")");
             }
             Bearbeitungverbund bearbeitungverbund = null;
             Connection connection = getConnection();
             String sql = "Select P.ID, P.VORNAME, P.NAME, P.STELLBE, P.GEBDATUM, v.id, v.pergrp, v.zda FROM PERSON P INNER JOIN VORGANG V ON p.id = v.personid WHERE P.IDBE= ? ORDER BY STELLBE ASC, p.gebdatum, v.pergrp";
             ResultSet resultSet = null;
             try {
             PreparedStatement statement = connection.prepareStatement(sql);
             statement.setInt(1, bvId);
             resultSet = statement.executeQuery();
             if (resultSet != null) {
             bearbeitungverbund = new Bearbeitungverbund(bvId);
             Person person = null;
             while (resultSet.next()) {
             int id = resultSet.getInt(1);
             //Neue Person
             if (! bearbeitungverbund.containsPerson(id)) {
             String vorname = resultSet.getString(2);
             String name = resultSet.getString(3);
             int stellbe = resultSet.getInt(4);
             Stellung stellung = Stellung.getStellungById(stellbe);
             Date geburtsDatum = resultSet.getDate(5);
             person = new Person(id, vorname, name, geburtsDatum, stellung);
             person.addVorgang(getVorgang(resultSet));
             bearbeitungverbund.addPerson(person);
             }
             //Nur neuer Fall der zur aktuellen Person hinzugefügt wird
             else {
             bearbeitungverbund.getPerson(id).addVorgang(getVorgang(resultSet));
             }
            
             }
             }
             else {
             log.info("Kein Bearbeitungsverbund für id " + bvId + " gefunden");
             }
             } catch (SQLException e) {
             log.error(e);
             }
            
            
             return bearbeitungverbund;
             }
            
             private Vorgang getVorgang(ResultSet resultSet) throws SQLException {
             int fallId = resultSet.getInt(6);
             int fall = resultSet.getInt(7);
             Personengruppenkennzeichen personengruppenkennzeichen = Personengruppenkennzeichen.getPersonengruppenkennzeichenById(fall);
             Date zdaDatum = resultSet.getDate(8);
             Vorgang vorgang = new Vorgang(fallId, zdaDatum, personengruppenkennzeichen);
             return vorgang;
             }
            
            }
            

            The beans are packaged in a jar.
            jboss.xml
            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
            
            <jboss>
            
             <security-domain>java:/jaas/MigvisLdapRealm</security-domain>
            
             <enterprise-beans>
            
             <!--
             To add beans that you have deployment descriptor info for, add
             a file to your XDoclet merge directory called jboss-beans.xml that contains
             the <session></session>, <entity></entity> and <message-driven></message-driven>
             markup for those beans.
             -->
            
             <session>
             <ejb-name>dzbw/migvis/Schnittstelle</ejb-name>
             <jndi-name>ejb/dzbw/migvis/Schnittstelle</jndi-name>
             <local-jndi-name>dzbw/migvis/SchnittstelleLocal</local-jndi-name>
            
             <method-attributes>
             </method-attributes>
             </session>
            
             <!--
             write a merge file jboss-webservices.ent for webservice-description
             -->
            
             </enterprise-beans>
            
             <resource-managers>
             </resource-managers>
            
             <!--
             | for container settings, you can merge in jboss-container.xml
             | this can contain <invoker-proxy-bindings/> and <container-configurations/>
             -->
            
            </jboss>
            

            ejb-jar.xml:
            <?xml version="1.0" encoding="UTF-8"?>
            
            <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
            
            <ejb-jar >
            
             <description><![CDATA[No Description.]]></description>
             <display-name>Generated by XDoclet</display-name>
            
             <enterprise-beans>
            
             <!-- Session Beans -->
             <session >
             <description><![CDATA[Die Klasse <code>SchnittstelleBean</code> dient als Fassadenbean.]]></description>
             <display-name>Schnittstelle</display-name>
            
             <ejb-name>dzbw/migvis/Schnittstelle</ejb-name>
            
             <home>de.dzbw.dnp.migvis.schnittstelle.SchnittstelleHome</home>
             <remote>de.dzbw.dnp.migvis.schnittstelle.Schnittstelle</remote>
             <local-home>de.dzbw.dnp.migvis.schnittstelle.SchnittstelleLocalHome</local-home>
             <local>de.dzbw.dnp.migvis.schnittstelle.SchnittstelleLocal</local>
             <ejb-class>de.dzbw.dnp.migvis.schnittstelle.SchnittstelleBean</ejb-class>
             <session-type>Stateless</session-type>
             <transaction-type>Container</transaction-type>
            
             <env-entry>
             <env-entry-name>DataSourceName</env-entry-name>
             <env-entry-type>java.lang.String</env-entry-type>
             <env-entry-value><![CDATA[java:/migvisDS]]></env-entry-value>
             </env-entry>
            
             </session>
            
             <!--
             To add session beans that you have deployment descriptor info for, add
             a file to your XDoclet merge directory called session-beans.xml that contains
             the <session></session> markup for those beans.
             -->
            
             <!-- Entity Beans -->
             <!--
             To add entity beans that you have deployment descriptor info for, add
             a file to your XDoclet merge directory called entity-beans.xml that contains
             the <entity></entity> markup for those beans.
             -->
            
             <!-- Message Driven Beans -->
             <!--
             To add message driven beans that you have deployment descriptor info for, add
             a file to your XDoclet merge directory called message-driven-beans.xml that contains
             the <message-driven></message-driven> markup for those beans.
             -->
            
             </enterprise-beans>
            
             <!-- Relationships -->
            
             <!-- Assembly Descriptor -->
             <!--
             To specify your own assembly descriptor info here, add a file to your
             XDoclet merge directory called assembly-descriptor.xml that contains
             the <assembly-descriptor></assembly-descriptor> markup.
             -->
            
             <assembly-descriptor >
             <!--
             To specify additional security-role elements, add a file in the merge
             directory called ejb-security-roles.xml that contains them.
             -->
            
             <!-- method permissions -->
             <!--
             To specify additional method-permission elements, add a file in the merge
             directory called ejb-method-permissions.ent that contains them.
             -->
             <method-permission >
             <description><![CDATA[description not supported yet by ejbdoclet]]></description>
             <unchecked/>
             <method >
             <description><![CDATA[description not supported yet by ejbdoclet]]></description>
             <ejb-name>dzbw/migvis/Schnittstelle</ejb-name>
             <method-name>*</method-name>
             </method>
             </method-permission>
            
             <!-- transactions -->
             <!--
             To specify additional container-transaction elements, add a file in the merge
             directory called ejb-container-transactions.ent that contains them.
             -->
             <container-transaction >
             <method >
             <ejb-name>dzbw/migvis/Schnittstelle</ejb-name>
             <method-name>*</method-name>
             </method>
             <trans-attribute>NotSupported</trans-attribute>
             </container-transaction>
            
             <!-- finder transactions -->
            
             <!-- message destinations -->
             <!--
             To specify additional message-destination elements, add a file in the merge
             directory called ejb-message-destinations.ent that contains them.
             -->
            
             <!-- exclude list -->
             <!--
             To specify an exclude-list element, add a file in the merge directory
             called ejb-exclude-list.xml that contains it.
             -->
             </assembly-descriptor>
            
            </ejb-jar>