Grails: Help with HQL query
I'm 开发者_如何学Pythonnot 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 ?
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.
精彩评论