开发者

Grails: Help with HQL query

开发者 https://www.devze.com 2022-12-24 17:01 出处:网络
I\'m 开发者_如何学Pythonnot very good in SQL and HQL... I have two domains: class Hotel { String name

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

精彩评论

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