title: JPA: Timestamp comparison in NamedQuery: time data lost
body: <p>I have a column destined to hold a timestamp which is defined with a java.util.Date data type and stored in a Oracle DATE type in the database.  I've verified that the full date and time information is persisted and retrieved correctly from the database, but when I try to compare it in a NamedQuery, the time information appears not to taken into account in the comparison. </p>
  
  <p>The column is defined as follows (analyzeDate is of type java.util.Date):</p>
  
  <pre><code>@Basic(optional = false)
  @Column(name = "ANALYZE_DATE")
  @Temporal(TemporalType.TIMESTAMP)
  private Date analyzeDate;
  </code></pre>
  
  <p>And my NamedQuery:</p>
  
  <pre><code>@NamedQuery(name = "BOADocument.findByBeforeAnalyzeDate", 
      query = "SELECT b FROM BOADocument b WHERE b.companyId = :companyId AND b.analyzeDate &lt; :analyzeDate")
  </code></pre>
  
  <p>Which I then execute, passing analyzeDate which is of type java.util.Date:</p>
  
  <pre><code>List&lt;BOADocument&gt; docs = em.createNamedQuery("BOADocument.findByBeforeAnalyzeDate") 
              .setParameter("companyId", clientRecord)
              .setParameter("analyzeDate", analyzeDate, TemporalType.TIMESTAMP)
              .getResultList()
  </code></pre>
  
  <p>I get back a list of all of the lines in the Document table, although they all have exactly the same value for analyzeDate as the value I've set as a parameter to the NamedQuery.  </p>
  
  <p>If I inverse the comparison, I get no lines, further convincing me that the time portion of the timestamp is being lost on the b.analyzeDate side of things, not the :analyzeDate side of things. </p>
  
  <p>I'm using JPA 1.0 with Hibernate 3.5.</p>
  
  <p>This is stumping me, and I'm close to giving up and using a native query, but that feels like cheating!</p>