views:

28

answers:

2

Hi all,

I've been trying to create a criteria builder containing a belongsTo relation and have yet to succeed. Consider the following model:

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

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

I'm trying to make the following query:

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

All I'm getting 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've tried to add different small additions to the criteria query like:

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

But still get the same problem.

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

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

Still not working.

Is there a way to use criteria builder containing a belongsTo query at all?

Thanks for your help in advance.
Lucien

A: 
def criteria = Msg.createCriteria()
results = criteria.list{
    user{
        eq("organisation", organisationInstance)
    }
}
Aaron Saunders
What's the difference from the example above?
Mr.B
your createCritia statement looks incorrect, missing "()"
Aaron Saunders