title: custom queries with Date input for Liferay
body: <p>I'm having problems in executing custom queries with Date inputs.
  here's my sql:</p>
  
  <pre><code>&lt;sql
       id="MyEntityFinder.findByIns"&gt;
   &lt;![CDATA[
       SELECT {EX_MyEntity.*}
       FROM EX_MyEntity
       WHERE
           (EX_MyEntity.myDate &gt;= ? AND EX_MyEntity.myDate &lt;= ?)
           ]]&gt;
  &lt;/sql&gt;
  </code></pre>
  
  <p>here's my finder MyEntityFinderImpl:</p>
  
  <pre><code>public class MyEntityFinderImpl extends BasePersistenceImpl&lt;MyEntity&gt; implements MyEntityFinder{
  
      public static final String FIND_BY_INS = "MyEntityFinder.findByIns";
      public List&lt;MyEntity&gt; findByIns(Date from, Date to, int begin, int end) throws SystemException{
      Session session = null;
      try {
          session = openSession();
          String sql = CustomSQLUtil.get(FIND_BY_INS);
          SQLQuery q = session.createSQLQuery(sql);
          q.setCacheable(false);
          q.addEntity("EX_MyEntity", MyEntityImpl.class);
          QueryPos qPos = QueryPos.getInstance(q);  
          qPos.add("%"+from+"%");
          qPos.add("%"+to+"%");
          return (List&lt;MyEntity&gt;) QueryUtil.list(q, getDialect(), begin, end);
      } catch (Exception e) {
          throw new SystemException(e);
      } finally {
          closeSession(session);
      }
  }    
  </code></pre>
  
  <p>}</p>
  
  <p>and here's how I call it from my jsp page:</p>
  
  <pre><code>Calendar aMonthAgo = Calendar.getInstance();
  aMonthAgo.set(Calendar.MONTH, aMonthAgo.get(Calendar.MONTH) - 1);
  Calendar now = Calendar.getInstance();
  List&lt;MyEntity&gt; monthly = MyEntityLocalServiceUtil.findByIns( 
                      new java.sql.Date(aMonthAgo.getTimeInMillis()),
          new java.sql.Date(now.getTimeInMillis()), 0,
          MyEntityLocalServiceUtil.getMyEntitysCount());
  </code></pre>
  
  <p>I'm getting "java.sql.SQLException: data exception: invalid datetime format" when trying to execute the query but I can't understand why.</p>