title: Why can't i compare java.util.Date to mysql dates?
body: <p>i have a strange situation:</p>
  
  <p>I'm using jpa/hibernate to get rows from a mySql DB table where a date column is greater or equal to a date i send in (stripped out irrelevant code):</p>
  
  <pre><code>SELECT sp.* FROM spaceproduct sp where sp.enddate is null or sp.enddate &gt;= :endDate)
  </code></pre>
  
  <p>in my code i basically do:</p>
  
  <pre><code>q.setParameter("endDate", new java.util.Date());
  </code></pre>
  
  <p>Now, my problem is when the date in the DB is the same date. i.e. "today", it doesn't get picked up. I assume that it's because it somehow also compares the time portion of the java.util.date to what's in the database (db value is "2011-10-28' only but the java.util Date is 2011-10-28T13:36:43.130+0200)</p>
  
  <p>However, if i change the date parameter i set into a java.sql.Date(), it works!</p>
  
  <p>Now, given that my mySql DB column is a Date, and not a DateTime, isnt this a bug? Even if i send in a java.util.date, shouldn't it only compare the date part since my DB column is a date?</p>
  
  <p>EDIT: i tried using a util-date and convert it into a sql-date. That actually doesn't work either:</p>
  
  <pre><code>java.util.Date utilDate = new java.util.Date();
  java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
  q.setParameter("endDate", sqlDate);
  </code></pre>
  
  <p>So from what i can see, i <em>have</em> to set the time part to 0 also for sql-dates, unless i use the deprecated "year-month-date" constructor...</p>