Oleksandr
Oleksandr

Reputation: 3801

Grails: Help with HQL query

I'm not very good in SQL and HQL...

I have two domains:

class Hotel {
 String name
}

class Room {
 Hotel hotel
 float price
}

How many hotels have at least one room ?

Upvotes: 1

Views: 1013

Answers (1)

Vincent Ramdhanie
Vincent Ramdhanie

Reputation: 103135

You probably want to make this a bi-directional relationship.

class Hotel {
 String name;
 List<Room> rooms;
}

class Room {
 Hotel hotel
 float price
}

Then HQL:

 from Hotel h where size(h.rooms) >= 1 

Will return Hotels where the rooms collection has at least one value.

More details here.

Upvotes: 2

Related Questions