1 Reply Latest reply on Aug 7, 2017 9:48 AM by Siddharth Sharan

    EJBLocalHome java.lang.ClassCastException - $$$view in class name

    Siddharth Sharan Newbie

      I am a Jboss beginner. I am trying to upgrade application running on Jboss 4 to Jboss AS 7 (Jboss-as-7.1.1.Final/JDK 7) on Windows.

      To start my initial experiment I simply put the .ear to Jboss 7 standalone/deployment folder with minor configuration change to the standalone.xml. The deployment in the server log seems good.

      But when I try to instantiate the EJB (Stateless session) bean through jndi. i am getting rather unusual classcast exception. The class of the local home object returned by jndi has an additional $$$view<number> added to it.

      Reason:Cannot cast com.cyberasp.common.server.dao.CasDAOHome$$$view97 to com.cyberasp.common.server.dao.CasDAOHome;

       

      Here is  the required code/config

      interface

      public interface CasDAOHome extends EJBLocalHome

      {

        public CasDAO create() throws CreateException;

      }

       

       

      ejb-jar.xml

      <?xml version="1.0"?>

      <!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>

          <enterprise-beans>

            <session>

              <ejb-name>casdao</ejb-name>

              <local-home>com.cyberasp.common.server.dao.CasDAOHome</local-home>

              <local>com.cyberasp.common.server.dao.CasDAO</local>

              <ejb-class>com.cyberasp.common.server.dao.CasDAOBean</ejb-class>

              <session-type>Stateless</session-type>

              <transaction-type>Container</transaction-type>

            </session>     

          </enterprise-beans>

          <assembly-descriptor>

              <container-transaction>

                  <method>

                      <ejb-name>casdao</ejb-name>

                      <method-name>*</method-name>

                  </method>

                  <trans-attribute>Supports</trans-attribute>

              </container-transaction>

          </assembly-descriptor>

        </ejb-jar>

       

      server.log

      10:36:48,317 DEBUG [org.jboss.as.ejb3] (MSC service thread 1-5) Installing timer service for component casdao

      10:36:48,333 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-5) JNDI bindings for session bean named casdao in deployment unit subdeployment "CasDao.jar" of deployment "c3unix.ear" are as follows:

       

      java:global/c3unix/CasDao/casdao!com.cyberasp.common.server.dao.CasDAOHome

      java:app/CasDao/casdao!com.cyberasp.common.server.dao.CasDAOHome

      java:module/casdao!com.cyberasp.common.server.dao.CasDAOHome

      java:global/c3unix/CasDao/casdao!com.cyberasp.common.server.dao.CasDAO

      java:app/CasDao/casdao!com.cyberasp.common.server.dao.CasDAO

      java:module/casdao!com.cyberasp.common.server.dao.CasDAO

       

      servlet code flow

       

      jndiName = "java:app/CasDao/casdao!com.cyberasp.common.server.dao.CasDAOHome";

      Hashtable<String, String> jndiProps = new Hashtable<String, String>();

          jndiProps.put("java.naming.factory.initial", "org.jboss.as.naming.InitialContextFactory");

          ctx = new InitialContext(jndiProps);

          Object dao = ctx.lookup(jndiName);

      EJBLocalHome daoEjbLocalHome = (EJBLocalHome) dao ;

      //daoEjbLocalHome.getClass().getName() -> cast com.cyberasp.common.server.dao.CasDAOHome$$$view97

      CasDAOHome casdaoHome = (CasDAOHome)daoEjbLocalHome;

      //classcast exception Reason:Cannot cast com.cyberasp.common.server.dao.CasDAOHome$$$view97 to com.cyberasp.common.server.dao.CasDAOHome;

       

      Addition information

      For experiment  I invoked create method on the daoEjbLocalHome through reflection. The method worked and return a CasDAO$$$view<number> instead of a CasDAO object.

       

      Any suggestion is appreciated.