Announcement Announcement Module
Collapse
No announcement yet.
Problem with Hibernate's Criteria and groupProperty Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with Hibernate's Criteria and groupProperty

    Hi guys,

    right now I'm translating some HQL-code into programmed Java code using the Criteria from Hibernate.

    I want to select some objects of the type Sector grouped by the sector.id and ordered by the size of its containing Publiction-Set. My HQL code is working fine:
    Code:
    SELECT sector FROM Sector AS sector LEFT JOIN sector.publications AS publication WHERE sector.name LIKE :firstCharacter GROUP BY sector.id
    My criteria-code looks like:

    Code:
    Criteria criteria = session.createCriteria(Sector.class)
    .createAlias("publications", "publication",Criteria.LEFT_JOIN)
    .setProjection(Projections.projectionList()
       .add(Projections.groupProperty("id"))
       .add(Projections.alias(Projections.count("publication.id"),"publicationCount")))
    .addOrder(sort("publicationCount", ascending))
    .addOrder(sort("name", ascending)).list();
    The order is correct, but I get list of Object[] containing the id and the publications count. Indeed this ist right, but I want to get a list only filled with Sector-Objects.

    Can someone can help me?

    THX

    Sebastian

  • #2
    You need to have an Entity with those properties (id and count).

    .setResultTransformer(IdCount.class);

    Comment

    Working...
    X