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

  • SEARCH
  • Home
  • 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 4589940
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:10:01+00:00 2026-05-21T22:10:01+00:00

I have an issue with grails criteria builder, I want to do a projection

  • 0

I have an issue with grails criteria builder, I want to do a projection on a column that is on a table that is in one-to-many relation to parent table example:

Car.createCriteria() { 
   projections { 
     property('name') 
     property('wheels.name')// ???? 
   }

   join 'wheels' 
   //or wheels {} ???
}

or something similar exist? I think it is basic propblem with aliases

  • 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-05-21T22:10:02+00:00Added an answer on May 21, 2026 at 10:10 pm

    I am assuming the following domain classes:

    class Car {
      String name
      static  hasMany = [wheels : Wheel]
    }
    
    class Wheel {
      String name
      static belongsTo = [car : Car]
    }
    

    I also assume that this is the desired output:

    CarName WheelName
    Car1    Wheel1
    Car1    Wheel2
    Car2    Wheel3
    

    In this case you would do this:

    void testCarProjectionItg() {
      def car1 = new Car(name: 'Car1').save()
      def car2 = new Car(name: 'Car2').save()
    
      def wheel1 = new Wheel(name: 'Wheel1')
      def wheel2 = new Wheel(name: 'Wheel2')
      def wheel3 = new Wheel(name: 'Wheel3')
    
      car1.addToWheels wheel1
      car1.addToWheels wheel2     
      car2.addToWheels wheel3
      wheel1.save()
      wheel2.save()
      wheel3.save()
      car1.save()
      car2.save()
    
      println Wheel.withCriteria {
        projections {
          property('name')
            car {
              property('name')
            }
        }       
      }
    }
    
    --Output from testCarProjectionItg--
    [[Wheel1, Car1], [Wheel2, Car1], [Wheel3, Car2]]
    

    I would prefer a HQL query in this case:

    println Wheel.executeQuery("select car.name, wheel.name from Car car inner join car.wheels wheel")
    --Output from testCarProjectionItg--
    [[Car1, Wheel1], [Car1, Wheel2], [Car2, Wheel3]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's the context of this issue: I have a Grails class: class User{ long
I have an example Grails application (from Grails in Action) that was created a
I am following the example in Grails in Action. I have an issue understanding
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
I have developed a Grails application and have deployed it many times to Heroku
I'm having an issue with my grails application. I have a form whose method
I'm just getting started with grails, and I'm having an issue. I have a
I have a frustrating problem with the criteria builder. I have an application in
I'm using Grails and I have a local-plugin (that I wrote) that I'm using
I want to use a snapshot version of the grails quartz plugin. The issue

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.