Unable to create grails Query criteria containing toTot relationship

I am trying to create a criteria builder containing the belongsTo relation and have not yet reached. Consider the following model:

class Msg {
    ...
    static belongsTo = [user: User]
    ...
}  

class User {
    ...
    Organisation organisation
    ...
}  

I am trying to make the following query:

Msg.createCriteria().list() {
    ...
    user {
        eq("organisation", organisationInstance)
    }
    ...
}

All I get is the following error

ERROR errors.GrailsExceptionResolver  - No signature of method: static User.call() is applicable for argument types: (MsgService$_findMessages_closure1_closure6) values: [MsgService$_findMessages_closure1_closure6@afcba8]
Possible solutions: save(), wait(), any(), getAll(), save(java.lang.Boolean), save(java.util.Map)

I tried to add various small additions to the query criteria, for example:

join "user"
fetchMode("user", org.hibernate.FetchMode.EAGER)

But still get the same problem.

I even tried adding the following static mapping to the Msg class:

static mapping = {
    columns {
        user lazy: false
    }
}

Still not working.

Is there a way to use the criteria builder containing the applyTo request?

Thanks for your help in advance. Lucien

+5
source share
2 answers

! . . : -)

+5
def criteria = Msg.createCriteria()
results = criteria.list{
    user{
        eq("organisation", organisationInstance)
    }
}
+2

All Articles