7 Replies Latest reply on Jan 16, 2006 10:47 PM by Vivek Srivastav

    Class Cast Exception with lookup

    Arthur Marinis Newbie

      I have spent hours trying to figure this one out. NOt sure if I am missing anything but I receive a ClassCastException when performing a context lookup and trying to cast to the interface.

      the problem occurs within a static method shown below
      public static TattsStore getSite() throws Exception
      {
      Log log = LogFactory.getLog( Utils.class );

      try {
      InitialContext ctx = new InitialContext();
      return (TattsStore)ctx.lookup(TattsStore.class.getName());
      } catch (Exception e) {
      e.printStackTrace();
      }
      }


      The Interface looks like this
      package com.valta.tatts.ejb;

      import java.util.List;
      import com.valta.tatts.par.*;

      public interface TattsStore {
      public List getAcccountTypes();
      }

      and the bean looks like this
      package com.valta.tatts.ejb;

      import java.util.List;

      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;

      import com.valta.tatts.par.AccountType;

      @Stateless(name="TattsStore")
      public class TattsStoreBean
      implements TattsStore {

      @PersistenceContext(unitName="stripesSyndicate")
      EntityManager em;

      public List getAcccountTypes() {
      return (List)em.createQuery("from AccountType c").getResultList();
      }

      }


      As you can see I have just copied the implementation of the DVD Store and made some minor changes.

      B elow is the initialisation of the ear file for this project and it appears correct.
      07:00:30,899 INFO [TomcatDeployer] undeploy, ctxPath=/stripesSyndicate, warUrl=.../tmp/deploy/tmp63602stripesSyndicate.ear-contents/stripesSyndicate.war/
      07:00:30,913 INFO [Ejb3Deployment] Create EntityManager with JNDI name: stripesSyndicate
      07:00:30,915 INFO [SessionFactoryImpl] closing
      07:00:30,993 INFO [EARDeployer] Undeploying J2EE application, destroy step: file:/development/jboss-4.0.3RC2/server/default/deploy/stripesSyndicate.ear
      07:00:31,017 INFO [EARDeployer] Init J2EE application: file:/development/jboss-4.0.3RC2/server/default/deploy/stripesSyndicate.ear
      07:00:31,414 INFO [JaccHelper] Initialising JACC Context for deployment: stripesSyndicate.ejb3
      07:00:31,425 INFO [Ejb3AnnotationHandler] found EJB3: ejbName=com.valta.tatts.ejb.TattsManagerBean, class=com.valta.tatts.ejb.TattsManagerBean, type=STATELESS
      07:00:31,464 INFO [JaccHelper] com.valta.tatts.ejb.TattsManagerBean has no @SecurityDomain - skipping JACC configuration
      07:00:31,470 INFO [Ejb3AnnotationHandler] found EJB3: ejbName=TattsStore, class=com.valta.tatts.ejb.TattsStoreBean, type=STATELESS
      07:00:31,487 INFO [JaccHelper] TattsStore has no @SecurityDomain - skipping JACC configuration
      07:00:31,500 INFO [JaccHelper] JACC Policy Configuration for deployment has been put in service
      07:00:31,500 INFO [Ejb3Deployment] EJB3 deployment time took: 86
      07:00:31,537 INFO [JaccHelper] Initialising JACC Context for deployment: stripesSyndicate.par
      07:00:31,542 INFO [Ejb3Deployment] Found persistence.xml file in EJB3 jar
      07:00:31,554 INFO [HibernatePersistence] found EJB3 Entity bean: com.valta.tatts.par.AccountType
      07:00:31,585 INFO [Configuration] processing extends queue
      07:00:31,586 INFO [Configuration] processing collection mappings
      07:00:31,680 INFO [Configuration] processing association property references
      07:00:31,722 INFO [Configuration] processing foreign key constraints
      07:00:31,727 INFO [Configuration] processing extends queue
      07:00:31,730 INFO [Configuration] processing collection mappings
      07:00:31,731 INFO [Configuration] processing association property references
      07:00:31,732 INFO [Configuration] processing foreign key constraints
      07:00:31,732 INFO [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.InjectedDataSourceConnectionProvider
      07:00:31,736 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
      07:00:31,739 INFO [SettingsFactory] RDBMS: MySQL, version: 5.0.12-beta-max
      07:00:31,740 INFO [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.2.0-alpha ( $Date: 2004/12/13 22:22:04 $, $Revision: 1.27.4.35.2.9 $ )
      07:00:31,741 INFO [Dialect] Using dialect: org.hibernate.dialect.MySQLDialect
      07:00:31,742 INFO [TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions)
      07:00:31,743 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
      07:00:31,743 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
      07:00:31,744 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
      07:00:31,744 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
      07:00:31,744 INFO [SettingsFactory] JDBC batch size: 15
      07:00:31,745 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
      07:00:31,745 INFO [SettingsFactory] Scrollable result sets: enabled
      07:00:31,745 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
      07:00:31,746 INFO [SettingsFactory] Connection release mode: after_statement
      07:00:31,746 INFO [SettingsFactory] Maximum outer join fetch depth: 2
      07:00:31,746 INFO [SettingsFactory] Default batch fetch size: 1
      07:00:31,747 INFO [SettingsFactory] Generate SQL with comments: disabled
      07:00:31,747 INFO [SettingsFactory] Order SQL updates by primary key: disabled
      07:00:31,747 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
      07:00:31,748 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
      07:00:31,748 INFO [SettingsFactory] Query language substitutions: {}
      07:00:31,748 INFO [SettingsFactory] Second-level cache: enabled
      07:00:31,749 INFO [SettingsFactory] Query cache: disabled
      07:00:31,749 INFO [SettingsFactory] Cache provider: org.jboss.ejb3.entity.TreeCacheProviderHook
      07:00:31,750 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
      07:00:32,189 INFO [SettingsFactory] Structured second-level cache entries: disabled
      07:00:32,190 INFO [SettingsFactory] Statistics: disabled
      07:00:32,190 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: enabled
      07:00:32,191 INFO [SettingsFactory] Default entity-mode: pojo
      07:00:32,195 INFO [SessionFactoryImpl] building session factory
      07:00:32,218 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
      07:00:32,219 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
      07:00:32,220 INFO [SessionFactoryImpl] Checking 0 named queries
      07:00:32,240 INFO [Ejb3Deployment] Create EntityManager with JNDI name: stripesSyndicate
      07:00:32,241 INFO [JaccHelper] JACC Policy Configuration for deployment has been put in service
      07:00:32,242 INFO [Ejb3Deployment] EJB3 deployment time took: 705
      07:00:32,329 INFO [ProxyDeployer] no declared remote bindings for : com.valta.tatts.ejb.TattsManagerBean
      07:00:32,351 INFO [ProxyDeployer] no declared remote bindings for : TattsStore
      07:00:32,359 INFO [EJB3Deployer] Deployed: file:/development/jboss-4.0.3RC2/server/default/tmp/deploy/tmp63604stripesSyndicate.ear-contents/stripesSyndicate.ejb3
      07:00:32,361 INFO [EJB3Deployer] Deployed: file:/development/jboss-4.0.3RC2/server/default/tmp/deploy/tmp63604stripesSyndicate.ear-contents/stripesSyndicate.par
      07:00:32,408 INFO [TomcatDeployer] deploy, ctxPath=/stripesSyndicate, warUrl=.../tmp/deploy/tmp63604stripesSyndicate.ear-contents/stripesSyndicate.war/
      07:00:32,638 WARN [AnnotatedClassActionResolver] this.configuration: net.sourceforge.stripes.config.DefaultConfiguration@d81fd5
      07:00:32,639 WARN [AnnotatedClassActionResolver] this.configuration.bootstrap: net.sourceforge.stripes.config.BootstrapPropertyResolver@b8ef9
      07:00:32,648 INFO [ResolverUtil] Checking URL 'file:/development/jboss-4.0.3RC2/server/default/tmp/deploy/tmp63604stripesSyndicate.ear-contents/stripesSyndicate.war/WEB-INF/classes/' for instances of net.sourceforge.stripes.action.ActionBean
      07:00:32,775 INFO [OgnlActionBeanPropertyBinder] Loaded validations for ActionBean com.valta.pages.DefaultLoader:{enter=@net.sourceforge.stripes.validation.Validate(maxlength=-1, converter=interface net.sourceforge.stripes.validation.TypeConverter, required=true, field=, mask=, minlength=-1)}
      07:00:32,803 INFO [DefaultLocalePicker] No locale list specified, defaulting to single locale: en_US
      07:00:32,823 INFO [StripesFilter] Stripes Initialization Complete. Version: 1.0.2, Build: 106
      07:00:32,981 INFO [EARDeployer] Started J2EE application: file:/development/jboss-4.0.3RC2/server/default/deploy/stripesSyndicate.ear


      When trying to execute the lookup I receive the following error
      07:01:01,617 ERROR [[StripesDispatcher]] Servlet.service() for servlet StripesDispatcher threw exception
      java.lang.ClassCastException: $Proxy146
      at com.valta.pages.Utils.getSite(Utils.java:25)
      at com.valta.pages.DefaultLoader.getDataSets(DefaultLoader.java:38)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at net.sourceforge.stripes.controller.DispatcherServlet.doPost(DispatcherServlet.java:132)
      at net.sourceforge.stripes.controller.DispatcherServlet.doGet(DispatcherServlet.java:54)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:173)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:157)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:613)


      Any ideas?