Hibernate criteria via session in grails


/ Published in: Groovy
Save to your folder(s)

see also http://floledermann.blogspot.com/2007/10/solving-hibernate-criterias-distinct.html


Copy this code and paste it in your HTML
  1. import com.lempa7.demandlempa.*
  2. import com.lempa7.demandlempa.enums.*
  3. import org.hibernate.Session
  4. import org.hibernate.SessionFactory
  5. import org.hibernate.criterion.*
  6.  
  7. SessionFactory sessionFactory = ctx.sessionFactory
  8. def session = sessionFactory.getCurrentSession()
  9. def criteria = session.createCriteria(TextOrder.class)
  10. //.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
  11. .setFirstResult(0).setMaxResults(5)
  12. .add( Restrictions.eq("status", TextOrderStatus.UNASSIGNED) )
  13. criteria.list()

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.