title: Hibernate Criteria extracting Year from date
body: <p>Im creating a hibernate criteria that will check if a contract is/has been valid during a year. The contract has a start and end-date as a standard date-field.</p>
  
  <p>So being used to SQL-SERVER, i would think something in the lines of this SQL:</p>
  
  <pre><code>SELECT * FROM CONTRACT WHERE YEAR(startDate) &lt;= ? AND YEAR(endDate) &gt;= ?
  </code></pre>
  
  <p>The questionmark is the given year as an integer.</p>
  
  <p>So how to transform this to a hibernate criteria?</p>
  
  <pre><code>int year = 2011; //Just a testyear for example purposes.
  DetachedCriteria criteria = DetachedCriteria.forClass(Contract.class)
      .add(Restrictions.le("startDate", year))
      .add(Restrictions.ge("endDate", year));
  </code></pre>
  
  <p>As you can see, i am missing the bit where i convert the date's to a year so it can be compared. Naturally my code does not run as it is.</p>
  
  <p>Any suggestion on how to get the desired results?</p>