我需要在grails.gorm.DetachedCriteria中添加子查询。
我尝试使用另一个grails.gorm.DetachedCriteria来完成此操作,但在本例中,我发现grails.gorm.DetachedCriteria不包含sqlRestriction()方法。
我还尝试使用instance.add(Subqueries.exists(subquqery))和hibernate org.hibernate.criterion.DetachedCriteria添加子查询,这种方法在我使用CriteriaBuilder时有效,但在grails.gorm.DetachedCriteria中不起作用,因为grails.gorm.DetachedCriteria不包含instance变量。
有谁可以帮我?
def result = DomainClass1.createCriteria().buildCriteria {
//some other conditions...
def subquery1 = DomainClass1.where {
//some other conditions...
def subquery2 = DomainClass2.where {
projections {
distinct 'id'
}
sqlRestriction 'timestamp < to_date(${date},'YYYYMMDDHH24MISS')'
}
eqAll 'id', subquery2
}
eqAll 'id', subquery1
}.list()发布于 2013-07-04 23:02:07
我认为你可以在不使用sqlRestriction的情况下实现你想要的。
def result = DomainClass1.createCriteria().buildCriteria {
//some other conditions...
def subquery1 = DomainClass1.where {
//some other conditions...
def subquery2 = DomainClass2.where {
//Assuming "timestamp" is the domain class property
//and not the column name and variable "date" is
//a string formatted date with the format 'yyyyMMddHHmmss'
timestamp.before(Date.parse('yyyyMMddHHmmss', date))
projections {
distinct 'id'
}
//sqlRestriction 'timestamp < to_date(${date},'YYYYMMDDHH24MISS')'
}
eqAll 'id', subquery2
}
eqAll 'id', subquery1
}.list()https://stackoverflow.com/questions/17468708
复制相似问题