I have the following SQL query that works like a champ:
select u.id
from morder_item mi
join book b on b.id = ${book.id}
join book_product bp on bp.book_id = b.id
join morder mo on mo.id = mi.morder_id
join user u on u.id = mo.user_id
where mi.book_product_id = bp.id
I’m trying to convert this to HQL but the problem is that all the examples I see are overly simple and don’t deal with joins at all. I need to get all the user ID’s but the query originates off of the MOrderItem domain. Any help is appreciated.
UPDATE: For the sake of someone trying to help do the conversion:
class MOrder {
static hasMany = [items: MOrderItem]
static belongsTo = [user: User]
}
class MOrderItem {
BookProduct bookProduct
static belongsTo = [morder: MOrder]
}
class User {
static hasMany = [morders: MOrder]
}
class BookProduct {
static belongsTo = [book: Book]
}
This seems to work with some contrived data: