4 Replies Latest reply on Mar 21, 2013 7:32 AM by Dan Berindei

    java.lang.CclassCastException: org.colfuturo.model.to.PaisTO cannot be cast to org.colfuturo.model.to.PaisTO

    Deibys Quintero Newbie

      Hello Guys,

       

      I am using InfiniSpan to manage a cache which could be managed across several web projects deployed in my JBOSS 7 AS server.

       

      I have defined a container called local-cache in JBOSS console

      In that container I have defined a "Local Cached" named  combo-cache.

       

      I have a war deployment which only resposibility It is to load the cache in an eagerly way.

       

       

      @WebServlet(name = "CacheServlet", loadOnStartup = 1)
      public class CacheServlet extends HttpServlet {
      
      
          /** */
          private static final long serialVersionUID = 1L;
      
      
          @Resource(mappedName = "java:jboss/infinispan/local-cache")
          private org.infinispan.manager.CacheContainer container;
      
      
          private org.infinispan.Cache<String, List<Object>> cacheCombo;
      
      
          private static final Logger logger = Logger.getLogger(CacheServlet.class.getName());
      
      
          @PersistenceContext(unitName = "entityManager")
          private EntityManager em;
      
      
          @EJB
          private IServicioCache bd;
      
      
          @PostConstruct
          public void initialize() {
                logger.info("Iniciando init()...");
      
       
      
                cacheCombo = container.getCache("combo-cache");
      
      
                try {
                    cacheCombo.put("paises", bd.getPaises());
                } catch (Exception ignored) {
                    cacheCombo.put("paises", null);
                }
        
                  logger.info("Finalizando init()...");
          }
      
      
      }
      
      

       

       

      As seen in the code, there is one element inserted in the cache "paises"  . Even though the cache is defined as List<Object>  , It is being inserted List<PaisTO> . I guess the casting is implicitely made

       

      public List<Object> getPaises() throws Exception {
                logger.info("Iniciando getPaises()...");
      
      
                List<Object> result = new ArrayList<Object>();
      
      
                try {
                    final String jpaQLQuery = "SELECT p FROM " + Pais.class.getSimpleName()
                              + " p WHERE p.homologar = false OR p.homologar IS NULL ORDER BY p.favorito DESC, p.nombre";
      
      
                    // jpaQLQuery
                    Query query = em.createQuery(jpaQLQuery);
      
      
                    List<Pais> paises = query.getResultList();
                    
                    for (Pais pais : paises) {
                          //SelectItem si = new SelectItem(pais.getId(), pais.getNombre());
                          result.add(pais.toPaisTO());
                    }
      
      
                } catch (Exception ex) {
                    logger.error("Ocurrió un error al consultar los paises....", ex);
                    throw ex;
                }
      
      
                logger.info("Finalizando getPaises()...");
      
      
                return result;
          }
      
      

       

       

      Now I want to access the cache element "paises"  from another war deployment in the same jboss as 7 instance. I do it in a SessionScopeBean

       

      @ManagedBean(name = "bean")
      @SessionScoped
      public class TestBean {
          
          @Resource(mappedName="java:jboss/infinispan/local-cache")
          private org.infinispan.manager.CacheContainer container;
          
          private org.infinispan.Cache<String, List<Object>> cache;
          
          List<Object> paises;
          
          @PostConstruct
          public void init() {
                cache = container.getCache("combo-cache");
                paises = cache.get("paises");
                if (paises != null) {
                    
                }
          }
          
          public List<Object> getPaises() {
                return paises;
          }
          
          public void  setPaises(List<Object> paises) {
                this.paises = paises;
          }
      
      

       

       

      In the same war , but in another class, I try to access the cache but I get classCastException.

      I am trying to downcast from Object to org.colfuturo.model.to.PaisTO  ( the exception occurs in the line in orange bellow)

       

      I have to say  that PaisTO implements Serializable , and the class is shared across the two projects through a same jar.

      The weird thing , It is that this line

      System.out.println(o.getClass().getName() + "-" + o.toString());

      prints

      org.colfuturo.model.to.PaisTO-PaisTO :: [3 - Alemania - null]

      which indicates that it should be posible to do the down-casting

       

       

      @Override
          public void encodeAll(FacesContext context) throws IOException {
                pais.setValue(null);
                List<Object> lista = (List<Object>) getAttributes().get("paises");
              List<SelectItem>  paisesOpciones = new ArrayList<SelectItem>();
              paisesOpciones.add(new SelectItem(null, "Seleccione...."));
      
      
                for (Object o  : lista) {
                    System.out.println(o.getClass().getName() + "-" + o.toString());
                    
                    //if (o instanceof org.colfuturo.model.to.PaisTO) {
                          org.colfuturo.model.to.PaisTO pais = (org.colfuturo.model.to.PaisTO) o;
                          paisesOpciones.add(new SelectItem(pais.getId(), pais.getNombre()));
                          System.out.println(pais.getId() + "-" +  pais.getNombre());
                    //}
              }
              setPaises(paisesOpciones);
                super.encodeAll(context);
          }
      
      

       

       

      The full stacktrace of the exception :

      15:34:32,503 GRAVE [javax.enterprise.resource.webcontainer.jsf.application] (http-localhost-127.0.0.1-8080-1) Error Rendering View[/index2.xhtml]: java.lang.ClassCastException: org.colfuturo.model.to.PaisTO cannot be cast to org.colfuturo.model.to.PaisTO

                at component.InputDate.encodeAll(InputDate.java:48) [classes:]

                at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402) [jsf-impl-2.1.7-jbossorg-2.jar:]

                at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125) [jsf-impl-2.1.7-jbossorg-2.jar:]

                at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121) [jsf-impl-2.1.7-jbossorg-2.jar:]

                at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]

                at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.7-jbossorg-2.jar:]

                at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]

                at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]

                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]

                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]

                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]

                at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_33]

       

       

      15:34:32,519 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/InfinispanWeb].[Faces Servlet]] (http-localhost-127.0.0.1-8080-1) Servlet.service() para servlet Faces Servlet lanzó excepción: java.lang.ClassCastException: org.colfuturo.model.to.PaisTO cannot be cast to org.colfuturo.model.to.PaisTO

                at component.InputDate.encodeAll(InputDate.java:48) [classes:]

                at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402) [jsf-impl-2.1.7-jbossorg-2.jar:]

                at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125) [jsf-impl-2.1.7-jbossorg-2.jar:]

                at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121) [jsf-impl-2.1.7-jbossorg-2.jar:]

                at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]

                at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.7-jbossorg-2.jar:]

                at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]

                at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]

                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]

                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]

                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]

                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]

                at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_33]

       

       

       

       

      What is the issue ?

      Isn´t it possible to put "custom" objects in the cache ?

      Does it have to do with that the different deployments may be loaded by different classloaders ?

      Any workaround ?

        • 1. Re: java.lang.CclassCastException: org.colfuturo.model.to.PaisTO cannot be cast to org.colfuturo.model.to.PaisTO
          Galder Zamarreño Master

          The easiest thing is probably to enable storeAsBinary in the configuration, and when reading the entry from the cache, call: cache.getAdvancedCache().with(...).get(...)

           

          The with() operation allows you to pass in a classloader to be used to deserialize the data read. So, each deployment would need to pass its classloader in the with().

          • 2. Re: java.lang.CclassCastException: org.colfuturo.model.to.PaisTO cannot be cast to org.colfuturo.model.to.PaisTO
            Deibys Quintero Newbie

            How do I set to "StoreAsBinary" ?

            Is there a draw-back for this feature ?

            Isn´t it possible to put in the infinispan cache "custom-typed" objects ?

             

            Besides, There is something I don´t understand, when  I put in the cache a List of javax.faces.model.SelectItem

            and I try to read it from the cache in another deployment in the same server , IT works good!,

             

            So , why doesn´t it happen the same when I put in the cache List<org.colfuturo.model.to.PaisTO> ?

             

            This is the code of PaisTO:


            package org.colfuturo.model.to;
            
            
            import java.io.Serializable;
            
            
            /**
             * 
             * @version 1.0, 11/10/2012
             * 
             */
            public class PaisTO implements Serializable {
            
            
                // ////////////////////////////////////////////////////////////////////////
                // Serial version UID
                // ////////////////////////////////////////////////////////////////////////
                /** */
                private static final long serialVersionUID = 1L;
            
            
                // ////////////////////////////////////////////////////////////////////////
                // Atributos de la clase
                // ////////////////////////////////////////////////////////////////////////
                /** */
                private Long id;
            
            
                /** */
                private String nombre;
            
            
                /** */
                private String nombreIngles;
            
            
                /** */
                private String nombreIdiomaOrigen;
            
            
                /** */
                private String codigoISO;
            
            
                /** */
                private Boolean favorito;
            
            
                /** */
                private Boolean homologar;
            
            
                /**
                 * @return Identificador del país
                 */
                public Long getId() {
                      return id;
                }
            
            
                // ////////////////////////////////////////////////////////////////////////
                // Getter/Setter de la clase
                // ////////////////////////////////////////////////////////////////////////
                /**
                 * @param id Identificador del país
                 */
                public void setId(Long id) {
                      this.id = id;
                }
            
            
                /**
                 * @return Nombre del país
                 */
                public String getNombre() {
                      return nombre;
                }
            
            
                /**
                 * @param nombre Nombre del país
                 */
                public void setNombre(String nombre) {
                      this.nombre = nombre;
                }
            
            
                /**
                 * @return El nombre del país en inglés
                 */
                public String getNombreIngles() {
                      return nombreIngles;
                }
            
            
                /**
                 * @param nombreIngles El nombre del país en inglés
                 */
                public void setNombreIngles(String nombreIngles) {
                      this.nombreIngles = nombreIngles;
                }
            
            
                /**
                 * @return Nombre del país en el idioma origen
                 */
                public String getNombreIdiomaOrigen() {
                      return nombreIdiomaOrigen;
                }
            
            
                /**
                 * @param nombreIdiomaOrigen Nombre del país en el idioma origen
                 */
                public void setNombreIdiomaOrigen(String nombreIdiomaOrigen) {
                      this.nombreIdiomaOrigen = nombreIdiomaOrigen;
                }
            
            
                /**
                 * @return Código ISO 3166 del país
                 */
                public String getCodigoISO() {
                      return codigoISO;
                }
            
            
                /**
                 * @param codigoISO Código ISO 3166 del país
                 */
                public void setCodigoISO(String codigoISO) {
                      this.codigoISO = codigoISO;
                }
            
            
                /**
                 * @return Indica si el país está en la lista de favoritos o no
                 */
                public Boolean getFavorito() {
                      if (this.favorito == null) {
                          this.favorito = false;
                      }
                      return favorito;
                }
            
            
                /**
                 * @param favorito Indica si el país está en la lista de favoritos o no
                 */
                public void setFavorito(Boolean favorito) {
                      this.favorito = favorito;
                }
            
            
                /**
                 * @return the homologar
                 */
                public Boolean getHomologar() {
                      return homologar;
                }
            
            
                /**
                 * @param homologar the homologar to set
                 */
                public void setHomologar(Boolean homologar) {
                      this.homologar = homologar;
                }
            
            
                /**
                 * Transforma el entity en TO
                 * @return El TO del entity
                 */
                public PaisTO toPaisTO() {
                      PaisTO paisTO = new PaisTO();
                      paisTO.setId(this.id);
                      paisTO.setNombre(this.nombre);
                      paisTO.setNombreIngles(this.nombreIngles);
                      paisTO.setNombreIdiomaOrigen(this.nombreIdiomaOrigen);
                      paisTO.setCodigoISO(this.codigoISO);
                      paisTO.setFavorito(this.favorito);
                      paisTO.setHomologar(this.homologar);
                      return paisTO;
                }
            
            
                /**
                 * Transforma el TO en entity
                 * @param paisTO EL TO a transformar
                 */
                public void fromPaisTO(PaisTO paisTO) {
                      if (paisTO != null) {
                          Long idPais = paisTO.getId();
                          if (idPais == null) {
                                idPais = null;
                                paisTO.setHomologar(true);
                          }
                          this.id = idPais;
                          this.nombre = paisTO.getNombre();
                          this.nombreIngles = paisTO.getNombreIngles();
                          this.nombreIdiomaOrigen = paisTO.getNombreIdiomaOrigen();
                          this.codigoISO = paisTO.getCodigoISO();
                          this.favorito = paisTO.getFavorito();
                          this.homologar = paisTO.getHomologar();
                      }
                }
            
            
                /**
                 * @see Object#toString()
                 */
                @Override
                public String toString() {
                      StringBuffer buff = new StringBuffer(this.getClass().getSimpleName() + " :: [" + this.id + " - " + this.nombre
                                + " - " + this.homologar + "]");
                      return buff.toString();
                }
            }
            
            

            • 3. Re: java.lang.CclassCastException: org.colfuturo.model.to.PaisTO cannot be cast to org.colfuturo.model.to.PaisTO
              Deibys Quintero Newbie

              By the way, I added a non-argument constructor and now I get more details in the stracjtrace:

               

              11:10:22,798 GRAVE [javax.enterprise.resource.webcontainer.jsf.application] (http-localhost-127.0.0.1-8080-2) Error Rendering View[/index2.xhtml]: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance

                        at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

                        at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:95) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

                        at org.jboss.as.web.deployment.component.WebComponentInstantiator$2.<init>(WebComponentInstantiator.java:96) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

                        at org.jboss.as.web.deployment.component.WebComponentInstantiator.initializeInstance(WebComponentInstantiator.java:94) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

                        at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:86) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

                        at org.jboss.as.web.deployment.jsf.JsfInjectionProvider.invokePostConstruct(JsfInjectionProvider.java:69) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

                        at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:223) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72) [jbossweb-7.0.13.Final.jar:]

                        at org.apache.el.parser.AstValue.getValue(AstValue.java:147) [jbossweb-7.0.13.Final.jar:]

                        at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189) [jbossweb-7.0.13.Final.jar:]

                        at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) [weld-core.jar:2012-10-12 10:00]

                        at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at javax.faces.component.UIOutput.getValue(UIOutput.java:169) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.7-jbossorg-2.jar:]

                        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]

                        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

                        at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core.jar:2012-10-12 10:00]

                        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]

                        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

                        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]

                        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]

                        at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]

                        at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

                        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]

                        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]

                        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]

                        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]

                        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]

                        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]

                        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]

                        at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_33]

              Caused by: java.lang.ClassCastException: org.colfuturo.model.to.PaisTO cannot be cast to org.colfuturo.model.to.PaisTO

                        at org.colfuturo.perfil.web.bean.TestBean.init(TestBean.java:106) [classes:]

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_33]

                        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.6.0_33]

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.6.0_33]

                        at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.6.0_33]

                        at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptorFactory$ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptorFactory.java:130) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

                        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                        at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:73) [jboss-as-weld-7.1.1.Final.jar:7.1.1.Final]

                        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                        at org.jboss.as.ee.component.ManagedReferenceFieldInjectionInterceptorFactory$ManagedReferenceFieldInjectionInterceptor.processInvocation(ManagedReferenceFieldInjectionInterceptorFactory.java:112) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

                        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                        at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:106) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

                        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                        at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

                        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                        at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                        at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

                        ... 56 more

              • 4. Re: java.lang.CclassCastException: org.colfuturo.model.to.PaisTO cannot be cast to org.colfuturo.model.to.PaisTO
                Dan Berindei Expert

                Deibys Quintero wrote:

                 

                How do I set to "StoreAsBinary" ?

                Is there a draw-back for this feature ?

                Isn´t it possible to put in the infinispan cache "custom-typed" objects ?

                 

                Besides, There is something I don´t understand, when  I put in the cache a List of javax.faces.model.SelectItem

                and I try to read it from the cache in another deployment in the same server , IT works good!,

                 

                So , why doesn´t it happen the same when I put in the cache List<org.colfuturo.model.to.PaisTO> ?

                 

                 

                It's certainly possible to put custom objects in Infinispan caches, if you try reading the object from the same WAR you'll see it works fine!

                 

                My guess is that you have a copy of the org.colfuturo.model.to.PaisTO class in each WAR, so each WAR has a different class named org.colfuturo.model.to.PaisTO and instances of one class cannot be cast to the other class.

                 

                Enabling the storeAsBinary configuration option (http://docs.jboss.org/infinispan/5.2/configdocs/urn_infinispan_config_5.2/complexType/configuration.storeAsBinary.html) like Galder should work, because then you'll be serializing the object when calling cache.put() and deserializing it when calling cache.get(). I don't think you need to use cache.with(...) though, the cache should pick up the correct classloader on initialization. The cache is also initialized with the classloader of the first application that called CacheContainer.getCache(...), so you also have to use the cache.getAdvancedCache().with(classloader).get(key) instead of a regular get call (see http://docs.jboss.org/infinispan/5.2/apidocs/org/infinispan/AdvancedCache.html#with%28java.lang.ClassLoader%29).

                 

                javax.faces.model.SelectItem works because both WARs load the same copy of the class, from an AS7 module. You can create your own module and put your common classes there, and then you won't need to use storeAsBinary: http://www.mastertheboss.com/jboss-as-7/how-to-install-a-module-on-jboss-as-7