3 Replies Latest reply on Jan 27, 2016 7:37 AM by salvuzzo

    java.lang.ClassCastException same Class

    salvuzzo

      Hello, I have one problem. I have an Application WEB (WAR) and an EJB (JAR). Inside the EJB the are model HIBERNATE. My application web, it makes a connetion to EJB, and l'otuput the called method is one entity Hibernate (User). This output (entity user),  it is assembled into another object the same type (user) but i get this error:

       

      error: java.lang.ClassCastException: model.user cannot be cast to model.user

          at web.test.ClassTest.retriveUser(ClassTest.java:1813) [classes:]

          at web.test.ClassTest.resolvedUser(ClassTest.java:137) [classes:]

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_45]

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_45]

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_45]

          at java.lang.reflect.Method.invoke(Method.java:497) [rt.jar:1.8.0_45]

          at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274) [struts-1.2.8.jar:1.2.8]

          at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194) [struts-1.2.8.jar:1.2.8]

          at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419) [struts-1.2.8.jar:1.2.8]

          at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224) [struts-1.2.8.jar:1.2.8]

          at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

          at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

          at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_45]

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_45]

          at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_45]

        • 1. Re: java.lang.ClassCastException same Class
          lafr

          If I understood you correctly, you're deploying the war and jar file on their own, not assembled together into one ear file, correct?

          Probably both files contain the class model.user.

          On runtime you have one class loader for the web application and one class loader for the EJB-jar file.

          Although both include the same class file, this are different classes because of the different class loaders.

          You might include a file named jboss-deployment-structure.xml into WEB-INF folder of your war file. Then no longer include the entity classes like model.user into your war file.

          With that you get access to the classes of the jar file from your war file.

           

          <?xml version="1.0" encoding="UTF-8"?>
          <jboss-deployment-structure>
              <deployment>
                  <dependencies>
                      <module name="deployment.abc.jar"/>
                  </dependencies>
              </deployment>
          </jboss-deployment-structure>
          
          

           

          Replace abc with name of your jar file.

          • 2. Re: java.lang.ClassCastException same Class
            salvuzzo

            yes, I in my web application, I include the module (in the modules) that contains the jar of 'EJB, but always the same error

            • 3. Re: java.lang.ClassCastException same Class
              salvuzzo

              do not ask me why, but reinstalling jboss wildfly 8.1 everything went