Grails 6 – Replacement for deprecated Hibernate Criteria .list() and .scroll()

1 week ago 4
ARTICLE AD BOX

I was on Grails 3.3.18 and I’m migrating to Grails 6.

Since upgrading, I get this warning in my logs:

org.hibernate.orm.deprecation - HHH90000022: Hibernate's legacy org.hibernate.Criteria API is deprecated; use the JPA javax.persistence.criteria.CriteriaQuery instead

In my code I was using Hibernate Criteria in two ways:

def list = Toto.createCriteria().list { eq('exemple', XXX) }

And for large datasets:

def listScrollable = Toto.createCriteria().scroll { eq('exemple', XXX) } while (listScrollable.next()) { Toto toto = listScrollable.get(0) }

I understand that now I should replace this with GORM where {} queries, for example:

def list = Toto.where { exemple == XXX }.list()

This works, but I cannot find an equivalent for scroll.

If I try:

def listScrollable = Toto.where { exemple == XXX }.scroll()

I get

No signature of method: org.grails.datastore.gorm.query.criteria.AbstractDetachedCriteria.scroll() is applicable for argument types: () values: []

What is the correct way to iterate efficiently over a large result set in Grails 6 now that Hibernate Criteria is deprecated?

Thanks

Read Entire Article