Problem using Hibernate Projections

Posted by Lucas on Stack Overflow See other posts from Stack Overflow or by Lucas
Published on 2010-03-30T20:56:46Z Indexed on 2010/03/30 21:23 UTC
Read the original article Hit count: 439

Hello! I'm using Richfaces + HibernateQuery to create a data list. I'm trying to use Hibernate Projections to group my query result. Here is the code:

final DetachedCriteria criteria = DetachedCriteria
     .forClass(Class.class, "c")
     .setProjection(Projections.projectionList()
     .add(Projections.groupProperty("c.id")));
     ...

in the .xhtml file i have the following code:

  <rich:dataTable width="100%" id="dataTable" value="#{myBean.dataModel}" var="row">
<f:facet name="header">
 <rich:columnGroup>
                 ......
 </rich:columnGroup>
</f:facet>
<h:column>
 <h:outputText value="#{row.id}"/>
</h:column>
<h:column>
 <h:outputText value="#{row.name}"/>
</h:column>

But when i run the page it gives me the following error:

Error: value="#{row.id}": The class 'java.lang.Long' does not have the property 'id'.

If i take out the Projection from the code it works correctly, but it doesn't group the result. So, which mistake could be happening here?

EDIT: Here is the full criteria:

final DetachedCriteria criteria = DetachedCriteria.forClass(Class.class, "c");

criteria.setFetchMode("e.zzzzz", FetchMode.JOIN);

criteria.createAlias("e.aaaaaaaa", "aa");
criteria.add(Restrictions.ilike("aa.information", "informations...."));

criteria.setProjection(Projections.distinct(Projections.projectionList()
        .add(Projections.groupProperty("e.id").as("e.id"))));

getDao().findByCriteria(criteria);

if i take the "setProjection" line it works fine. I don't understand why it gives that error putting that line.

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about detachedcriteria