1 Reply Latest reply on Dec 7, 2006 9:34 AM by Attila Soos

    ClassCastException when trying to marshal MySql Datetime

    Attila Soos Newbie

      I get this Exception when I call my WebService. I use JBoss 4.0.5.GA, MySql JDBC Driver mysql-connector-java-3.1.14, and Hibernate. In my Pojo Class I've mapped the datetime Fields as java.util.Date, and in wsdl file as dateTime. My webService works without datetime fields perfectly.

      09:58:29,538 ERROR [SOAPFaultExceptionHelper] SOAP request exception
      javax.xml.rpc.JAXRPCException: Cannot create or send response message
      at org.jboss.ws.server.ServiceEndpoint.postProcessResponse(ServiceEndpoint.java:286)
      at org.jboss.ws.server.ServiceEndpoint.handleRequest(ServiceEndpoint.java:211)
      at org.jboss.ws.server.ServiceEndpointManager.processSOAPRequest(ServiceEndpointManager.java:355)
      at org.jboss.ws.server.StandardEndpointServlet.doPost(StandardEndpointServlet.java:115)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.jboss.ws.server.StandardEndpointServlet.service(StandardEndpointServlet.java:76)
      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 org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      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.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
      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:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      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:595)
      Caused by: javax.xml.rpc.JAXRPCException: java.lang.ClassCastException: java.sql.Timestamp
      at org.jboss.ws.soap.SOAPContentElement.write(SOAPContentElement.java:986)
      at org.jboss.ws.soap.SAAJElementWriter.writeElement(SAAJElementWriter.java:171)
      at org.jboss.ws.soap.SAAJElementWriter.writeElement(SAAJElementWriter.java:184)
      at org.jboss.ws.soap.SAAJElementWriter.writeElement(SAAJElementWriter.java:184)
      at org.jboss.ws.soap.SAAJElementWriter.writeElement(SAAJElementWriter.java:184)
      at org.jboss.ws.soap.SAAJElementWriter.printInternal(SAAJElementWriter.java:163)
      at org.jboss.ws.soap.SAAJElementWriter.print(SAAJElementWriter.java:142)
      at org.jboss.ws.soap.SAAJElementWriter.printSOAPElement(SAAJElementWriter.java:91)
      at org.jboss.ws.server.ServiceEndpoint.postProcessResponse(ServiceEndpoint.java:280)
      ... 25 more
      Caused by: java.lang.ClassCastException: java.sql.Timestamp
      at org.jboss.xb.binding.SimpleTypeBindings.marshal(SimpleTypeBindings.java:1150)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalCharacters(MarshallerImpl.java:995)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalSimpleType(MarshallerImpl.java:471)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalElementType(MarshallerImpl.java:415)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalElement(MarshallerImpl.java:331)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalElementOccurence(MarshallerImpl.java:311)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalParticle(MarshallerImpl.java:730)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalModelGroupSequence(MarshallerImpl.java:920)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalModelGroup(MarshallerImpl.java:860)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalParticle(MarshallerImpl.java:641)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalComplexType(MarshallerImpl.java:608)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalElementType(MarshallerImpl.java:419)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalElement(MarshallerImpl.java:331)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshalElementOccurence(MarshallerImpl.java:311)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshallInternal(MarshallerImpl.java:210)
      at org.jboss.xb.binding.sunday.marshalling.MarshallerImpl.marshal(MarshallerImpl.java:168)
      at org.jboss.ws.jaxb.JBossXBMarshallerImpl.marshal(JBossXBMarshallerImpl.java:146)
      at org.jboss.ws.jaxrpc.encoding.JAXBSerializer.serialize(JAXBSerializer.java:107)
      at org.jboss.ws.soap.SOAPContentElement.getXMLFragment(SOAPContentElement.java:157)
      at org.jboss.ws.soap.SOAPContentElement.expandToDOM(SOAPContentElement.java:817)
      at org.jboss.ws.soap.SOAPContentElement.handleMTOMTransitions(SOAPContentElement.java:1015)
      at org.jboss.ws.soap.SOAPContentElement.write(SOAPContentElement.java:968)
      ... 33 more

      I call this function in my WebService:

      Session hsession = null;
      User user = null;
      try {



      InitialContext ctx = new InitialContext();
      SessionFactory factory = (SessionFactory) ctx
      .lookup("java:/hibernate/MySqlRw");
      hsession = factory.openSession();
      Criteria crit = hsession.createCriteria(User.class);

      crit.add(Expression.eq("user_login_name", name));

      List resultList = crit.list();
      System.out.println("Size: " + resultList.size());
      if (resultList.size() > 0) {
      Iterator it = resultList.iterator();

      while (it.hasNext()) {

      user = (User) it.next();

      }
      }

      } catch (Exception ex) {
      ex.printStackTrace();
      } finally {

      hsession.close();
      }
      return user;