title: JPA: directly mapping collection size to attribute using count?
body: <p>Class <code>A</code> has a one-to-many relationship to <code>B</code>. Hence, <code>A</code> has an attribute <code>collectionOfB</code>.</p>
  
  <p>Is there any way I could map "count B" to single attribute in <code>A</code>?</p>
  
  <p>The purpose would be to offer a shortcut to retrieve the number of associated <code>B</code>s without loading the entire collection. Sometimes all I need is the count i.e. the collection size. I know I could issue a query against the entity manager that does exactly that. However, seeing it done by the JPA provider thanks to annotations would of course be preferable.</p>