golly97 wrote:
Hello,
Is there an easy way of counting records that where selected in a named query, before i get the results in a collection??
I want to count the number of records before I apply my paging, using
setFirstResult
setMaxResults
I know that I can do it with criteria, buy using
criteria.setProjection(Projections.rowCount());
thank you
Hello,
I'm also new to Hibernate and I dont know if this is the correct approach but what I have done in this case is:
Add a new attribute to POJO class that is not associated with any table field, and in this case Hibernate will not try to save it to back-end.
Sample:
Sample for Issue xml definition.
...
<property name="articlesNo" type="long"
formula="( SELECT COUNT(A.id_Article) FROM tblArticles A WHERE A.id_Issue=id_Issue )"/>
...
<set name="articlesVO" inverse="true" lazy="true" cascade="all" order-by="position ASC">
<key column="id_Issue" not-null="true"/>
<one-to-many class="...ArticleVO"/>
</set>
....
Hope this help
OO