Grails DetachedCriteria不包含sqlRestriction

时间:2013-07-04 11:06:53

标签: grails gorm

我需要将子查询添加到grails.gorm.DetachedCriteria

我试图通过其他grails.gorm.DetachedCriteria执行此操作,但在这种情况下,我发现grails.gorm.DetachedCriteria不包含方法sqlRestriction()

此外,我尝试使用instance.add(Subqueries.exists(subquqery))和hibernate org.hibernate.criterion.DetachedCriteria添加子查询,这种方式在我使用CriteriaBuilder时有效,但在grails.gorm.DetachedCriteria中它不起作用,因为{ {1}}不包含grails.gorm.DetachedCriteria变量。

任何人都可以帮助我吗?

instance

1 个答案:

答案 0 :(得分:0)

我认为您可以在不使用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()