title: Using GROUP BY with OpenJPA
body: <p>I'm using OpenJPA to load comments from my database into comment objects.  Comment objects also have categories, sources (string), and comment time fields.  This works great with OpenJPA, and I like my Comment object to the Comment table, and all is right with the world.</p>
  
  <p>For a summary view, I'm interested in doing a GROUP BY query on the categories and sources so that for each source, I can see a break down of how many comments are available.</p>
  
  <pre><code>SELECT source, category, count(category) FROM Comments GROUP BY source,category
  </code></pre>
  
  <p>Now, my idea was to create this query using the entity manager, and have it somehow use a CommentSummary object instead of the Comment object.  I have no idea how to tell OpenJPA how to do this.  It seems like all the examples of using the GROUP BY do not consider also getting the base objects themselves.</p>
  
  <p>I tried creating a view called 'CommentSummary', but OpenJPA wanted to modify the table to add an id field - perhaps if I simply told it the source and category fields were the primary keys it would work.  I'm just a little confused that this isn't addressed directly anywhere that I can understand maps to my problem.</p>
  
  <p>Has anyone done this successfully?  What should I be doing differently?</p>