title: Hibernate result grouping by year/month of date
body: <p>for a near-classical task of displaying sale statistics for articles over a given time period, I stumbled across an interesting question: Given, I have a database table with article numbers, amounts and dates and I want to group the articles with their amounts first by year (for the last two years for the overview) and for a refined detail view by month.</p>
  
  <p>My solutions so far were both based on the Hibernate-Entity-approach, insofar as I requested the entities and grouped them in Java with the following strategies</p>
  
  <ol>
  <li>Request all entries from the table (1 SQL request).</li>
  <li>Request only the entries for a given period (2 SQL requests for the year overview, 12 requests for the month diagram).</li>
  </ol>
  
  <p>I wondered whether there is a more practical approach using the advantages of SQL (with Hibernate), ideally without any grouping code in Java and I created a little SQL Fiddle example (<a href="http://sqlfiddle.com/#!2/97a5d" rel="nofollow">http://sqlfiddle.com/#!2/97a5d</a>) to demonstrate the results (2013: 8 articles, 2012: 18 articles // September 2013: 5 articles, June 2013: 3 articles, June 2012: 7 articles, February 2012: 11 articles).</p>
  
  <p>Thank you so far,
  Smutje</p>