title: Compare java.util.Date with MySQL date
body: <p>I'm trying to compare a <strong>java.util.date</strong> with a <strong>date</strong> type in MYSQL with HQL and no solution found has solved my problem.</p>
  <p>My method is</p>
  <pre><code>    public List&lt;Person&gt; getPersonByNameandBirth(String name, Date birth) {
          Session sesion = factoria.getCurrentSession();
          Query&lt;Person&gt; query = sesion.createQuery(
                  &quot;FROM Person WHERE name = :n AND birth = :date ORDER BY name&quot;,
                  Person.class);
          ;
          query.setParameter(&quot;n&quot;, name);
          SimpleDateFormat sdf = new SimpleDateFormat (&quot;yyyy-MM-dd&quot;);
          String date = sdf.format(birth);
          System.out.println(date);
          query.setParameter(&quot;date&quot;, date);
  
          List&lt;Person&gt; people = query.getResultList();
  
          return people;
      }
  </code></pre>
  <p>With this code I get the exception</p>
  <pre><code>java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.Date (java.lang.String and java.util.Date are in module java.base of loader 'bootstrap')
      org.hibernate.type.descriptor.java.JdbcTimestampTypeDescriptor.unwrap(JdbcTimestampTypeDescriptor.java:24)
      org.hibernate.type.descriptor.sql.TimestampTypeDescriptor$1.doBind(TimestampTypeDescriptor.java:48)
      org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:73)
      org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:276)
      org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:271)
      org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:53)
      org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:648)
      org.hibernate.loader.Loader.bindPreparedStatement(Loader.java:2131)
      org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:2108)
      org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2040)
      org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2018)
      org.hibernate.loader.Loader.doQuery(Loader.java:948)
      org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:349)
      org.hibernate.loader.Loader.doList(Loader.java:2849)
      org.hibernate.loader.Loader.doList(Loader.java:2831)
      org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2663)
      org.hibernate.loader.Loader.list(Loader.java:2658)
      org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:506)
      org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:400)
      org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219)
      org.hibernate.internal.SessionImpl.list(SessionImpl.java:1414)
      org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1625)
      org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1593)
      org.hibernate.query.Query.getResultList(Query.java:165)
      com.spring.model.dao.PersonDAOImpl.getPersonByNameandBirth(PersonDAOImpl.java:152)
      com.spring.model.services.PersonService.getPersonByNameAndBirth(PersonService.java:53)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
      java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.base/java.lang.reflect.Method.invoke(Method.java:564)
      org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
      org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
      org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
      com.sun.proxy.$Proxy95.getPersonByNameAndBirth(Unknown Source)
      com.spring.controller.PersonController.postPersonName(PersonController.java:147)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
      java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.base/java.lang.reflect.Method.invoke(Method.java:564)
      org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
  
  </code></pre>
  <p>I have also tried just setting the parameter without DateFormat (no results, empty list).
  Also, with to_char function (exception because it says it doen's exist).</p>
  <p>Thanks in advance.</p>