开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜