1 Reply Latest reply on Apr 28, 2009 12:31 PM by Murat ALPAY

    cannot convert java.lang.String to java.util.date error

    jaya kemmannu Newbie
      Hi i'm getting following error when i run my application

      Error:

      14:27:55,987 ERROR [application] /PolicyList.xhtml @24,131 action="#{policySearch.find}": javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
      javax.faces.el.EvaluationException: /PolicyList.xhtml @24,131 action="#{policySearch.find}": javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
      .....
      .....
      Caused by: javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
           at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
      .......
      .......
      Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
           at org.hibernate.type.DateType.toString(DateType.java:78)
           at org.hibernate.type.NullableType.nullSafeToString(NullableType.java:93)
      ....
      ....
      14:27:56,002 WARN  [lifecycle] #{policySearch.find}: /PolicyList.xhtml @24,131 action="#{policySearch.find}": javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
      javax.faces.FacesException: #{policySearch.find}: /PolicyList.xhtml @24,131 action="#{policySearch.find}": javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
           
      .....
      Caused by: javax.faces.el.EvaluationException: /PolicyList.xhtml @24,131 action="#{policySearch.find}": javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
           at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:73)
           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
           ... 51 more
      Caused by: javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
           at
      .......
      Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
      ......
      14:27:56,002 WARN  [ExceptionFilter] handling uncaught exception
      javax.servlet.ServletException: #{policySearch.find}: /PolicyList.xhtml @24,131 action="#{policySearch.find}": javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
      .....
      Caused by: javax.faces.FacesException: #{policySearch.find}: /PolicyList.xhtml @24,131 action="#{policySearch.find}": javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
      ...
      Caused by: javax.faces.el.EvaluationException: /PolicyList.xhtml @24,131 action="#{policySearch.find}": javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
           at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:73)
           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
           ... 51 more
      Caused by: javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
           at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
           at org.
      .....
      Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
      .........
      .........
      14:27:56,002 WARN  [ExceptionFilter] exception root cause
      javax.faces.FacesException: #{policySearch.find}: /PolicyList.xhtml @24,131 action="#{policySearch.find}": javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
      .......
      .......
      Caused by: javax.faces.el.EvaluationException: /PolicyList.xhtml @24,131 action="#{policySearch.find}": javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
           at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:73)
           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
           ... 51 more
      Caused by: javax.ejb.EJBTransactionRolledbackException: java.lang.String cannot be cast to java.util.Date
           at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
           at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
           at o
      .....
      Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
           at org.hibernate.type.DateType.toString(DateType.java:78)
           at org.hibernate.type.NullableType.nullSafeToString(NullableType.java:93)
           
      policySearchingAction.java

      ........
      ........
      private void queryPolicy() {
                List<Policy> results = em.createQuery("select p from Policy p where lower(p.policyId) like #{patern} or lower(str(p.policyStartDate)) like #{pattern} or lower(str(p.policyEndDate)) like #{pattern} or lower(p.customer.customerId) like #{pattern} or lower(p.policytype.policyTypeId) like #{pattern} ")
              .setMaxResults(pageSize+1)
              .setFirstResult(page * pageSize)
              .getResultList();
             
             ..........
          }

      policylist.xhtml
      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://jboss.com/products/seam/taglib"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:rich="http://richfaces.org/rich"
          xmlns:a="http://richfaces.org/a4j"
          template="layout/template.xhtml">
         

      <ui:define name="body">

          <h:form id="searchCriteria" styleClass="edit">

              <rich:simpleTogglePanel label="Search Policies" switchType="ajax">

                  <s:decorate template="layout/display.xhtml">
                     
                      <h:inputText id="searchString" value="#{policySearch.searchString}" />
                        <a:support id="onkeyup" event="onkeyup" actionListener="#{policySearch.find}"   reRender="searchResults">                         
                        </a:support>&#160;
                        <a:commandButton id="findPolicies" value="Find Policies" action="#{policySearch.find}" reRender="searchResults"></a:commandButton>
                  </s:decorate>
                  <s:decorate template="layout/display.xhtml">
                    <h:outputLabel id="maximumResultsLabel" for="pageSize" > Maximum Results </h:outputLabel>
                      <h:selectOneMenu id="pageSize" value="#{policySearch.pageSize}" style=" width : 72px;">
                               <f:selectItem id="PageSize5" itemLabel="5" itemValue="5"/>
                               <f:selectItem id="PageSize10" itemLabel="10" itemValue="10"/>
                               <f:selectItem id="PageSize20" itemLabel="20" itemValue="20"/>
                            </h:selectOneMenu></s:decorate>
                    </rich:simpleTogglePanel>
               </h:form>
               
               <rich:panel id="searchResults">
                        <h:outputLabel id="NoPoliciesFoundMessage" value="No Policies Found" rendered="#{policy !=null  and policy.rowCount==0}" />
                       
                        <rich:dataTable id="policy" value="#{policy}" var="cla" rendered="#{policy.rowCount>0}">
                            <h:column id="column1">
                                <f:facet id="PolicyIDFacet" name="header">PolicyID</f:facet>
                                   #{cla.policyId}
                            </h:column>
                           
                            <h:column id="column2">
                                <f:facet id="PolicyStartDate" name="header">PolicyStartDate</f:facet>
                                  #{cla.policyStartDate}
                            </h:column>
                           
                            <h:column id="column3">
                            <f:facet id="PolicyEndDate" name="header">Policy End Date</f:facet>
                                #{cla.policyEndDate}
                            </h:column>
                             
                            
                            <h:column id="column5">
                                 <f:facet id="CustomerIDFacet" name="header">CustomerID</f:facet>
                                     #{cla.customer.customerId}
                               </h:column>
                             
                              <h:column>
                                 <f:facet id="PolicyTypeIDFacet" name="header">PolicyTypeID</f:facet>
                                     #{cla.policytype.policyTypeId}
                                </h:column>
                              
                        </rich:dataTable>
                        <s:link id="MoreResultsLink" value="More results" action="#{policySearch.nextPage}" rendered="#{policySearch.nextPageAvailable}"/>
                       
                </rich:panel>
      </ui:define>

      </ui:composition>