有什么办法可以查询(标准)单向多对一关系中一侧受限的多方列表
域
class Batch {
String name
Date date
}
class Record {
String type
Batch batch
}
class RecordDetails {
String xx
Record record
}
无论如何,是否有条件查询所有批次记录,其中batch.date = xx,而record.type = yy和recordDetails.xx = zz
HQL应该可以工作,但是除了查询中的条件以外,还有其他方法可以使用。
最佳答案
如果没有查询的地方查询和分离的条件,则一个选项将使用sqlRestriction
,如下所示:
Batch.withCriteria {
sqlRestriction """
exists (
select * from record r
join record_details rd on rd.record_id = r.id
where
r.batch_id = {alias}.id and
r.type like ? and
rd.xx like ?
)""", [ 'foo', 'bar' ]
}
关于hibernate - Grails单向多对一和标准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26973464/