Results 1 to 2 of 2

Thread: Problem with Hibernate's Criteria and groupProperty

  1. #1
    Join Date
    Apr 2009
    Location
    Stuttgart, Germany
    Posts
    1

    Question 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. #2
    Join Date
    Sep 2008
    Posts
    2

    Default

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

    .setResultTransformer(IdCount.class);

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •