Saturday, August 21, 2010

Distinct selection

Found a nice way of doing a distinct sql selection using the Gorm criteria.
You just use a critera and a projections (hibernate)
        def criteria = DomainObj.createCriteria()
        def date = new Date()
        def list = criteria {
            and {
                gt('endDate', date)
                lt('beginDate', date)
            }            
            projections {
                distinct('term')
            }
        } 

No comments:

Post a Comment