Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9080533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:05:48+00:00 2026-06-16T20:05:48+00:00

assuming following: public class Enterprise { private int id; private String name; } public

  • 0

assuming following:

public class Enterprise
{
   private int id;
   private String name;
}
public class Site
{
   private int id;
   private String name;
   private Enterprise enterprise; //@ManyToOne relation
}
public class Area
{
   private int id;
   private String name;
   private Site site; //@ManyToOne relation
}

I would like to do execute query using hibernate criteria grouping result by enterprise.

    Criteria criteria = session.createCriteria(Area.class);
    criteria.setProjection(Projections.projectionList()  
                    .add(Property.forName("id").as("id")) 
                    .add(Property.forName("name").as("name"))
        .add(Projections.groupProperty("site.enterprise")))
        .setResultTransformer(Transformers.aliasToBean(Area.class));
/*
 * more conditions
 */
    List<Area> areas = criteria.list();

When executing this hibernate returns exeption: org.hibernate.QueryException : could not resolve property: site.enterprise …

Is there some elegant way how to do this. Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:05:49+00:00Added an answer on June 16, 2026 at 8:05 pm

    You may need to set the alias first I believe:

    criteria.createAlias("site", "s")
    

    And then use:

    Projections.groupProperty("s.enterprise")
    

    You may also need to group on a field and not the entity, so:

    site.enterprise.name // or id
    

    This may require you to create an alias for enterprise too but you may not need to.

    UPDATE 1: You could end up with something like this:

    Criteria criteria = session.createCriteria(Area.class);
    criteria.createAlias("site", "s")
            .createAlias("s.enterprise", "e")
            .setProjection(Projections.projectionList()  
                    .add(Property.forName("id").as("id")) 
                    .add(Property.forName("name").as("name"))
        .add(Projections.groupProperty("s.e.name")))
        .setResultTransformer(Transformers.aliasToBean(Area.class));
    

    UPDATE 2: Call me crazy but from the example above, you may be taking a very long-winded approach by not using Hibernate to its full potential – it seems like you’re trying to use it as you would SQL. Hibernate already knows about your entities, their fields and relationships. In my eyes, this is equivalent to the above:

    Criteria criteria = session.createCriteria(Area.class);
    criteria.createAlias("site", "s")
            .createAlias("s.enterprise", "e")
            .add(Projections.groupProperty("s.e.name"));
    
    // Any other conditions.
    
    List<Area> areas = criteria.list();
    

    I’m not even sure why you’re grouping it at the moment…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming the following view model definition: public class MyObject { public string Name {
Assuming the following: public class Order { public virtual int OrderId {get;set} public virtual
Assuming this class: public class AmIThreadSafe { private int a; private int b; AmIThreadSafe(int
Assuming the following class stub: public class Foo<T> { private Class<T> type; public Foo<T>
I would like to do the following: public class ImmutableList<T> { public <U super
Say for example I have the following type: public class Site { public string
Assuming the following hypothetical inheritance hierarchy: public interface IA { int ID { get;
I have a Java class which is something like the following: public class Foo{
I have the following model: public class Blog { public int BlogID { get;
Lets say i have the following scenario: public class A { public String createString(final

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.