createcriteria

Grails 2.x createCriteria 'or' doesn't work for nested associations

你。 提交于 2019-11-29 21:07:52
问题 It seems that in Grails 2.x, if you have a domain class association, and you try to run a createCriteria using or on that relation + another query, the or will ignore the other query and just use the results of the nested association. I realize this may be a little confusing, so here is an example: class Passenger { Long id Boolean isDriving } class Car { Long id Passenger passenger Boolean isMoving static constraints = { passenger nullable: true } } and a test: class CarIntegrationTests {

Is there a 'contains' functionality on a collection property of a domain object for createCriteria?

只愿长相守 提交于 2019-11-29 13:20:38
I have an Auction domain object and a User domain object. An Auction hasMany Users. What I'd like to do, using createCriteria , is something like this: def c = Auction.createCriteria() def l = c.list (max: maxVar, offset: offsetVar) { contains("users", thisUser) } Though, contains is not in the list of acceptable nodes: createCriteria description page . Is there any way to implement this functionality? To be clear, is there a way to have the criteria be that a specified User object is contained within a collection property of the Auction? Try this: def l = c.list (max: maxVar, offset:

hibernate - createCriteria or createAlias?

点点圈 提交于 2019-11-27 18:32:58
If I want to search those students who take class "Math" and "John" is his group: shoud I use createCriteria or createAlias? Criteria: Criteria criteria = session.createCriteria(Student.class); Criteria subquery1 = criteria.createCriteria("courses", course).add(Restrictions.eq(course.name, "Math")); Criteria subquery2 = criteria.createCriteria("group", student).add(Restrictions.eq(student.name, "John")); how to put subquery1 and subquery2 together with initial criteria? Alias: Criteria criteria = session.createCriteria(Student.class). createAlias("courses", course).add(Restrictions.eq(course