5

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

Mr.B
  • 917
  • 1
  • 11
  • 20

2 Answers2

7

I've found the solution! The problem wasn't related to criteria builder at all. In this instance, I had a user variable inside the scope. Once a removed it it works like a charm :-)

Mr.B
  • 917
  • 1
  • 11
  • 20
  • 1
    it helped after banging my head for long time. Error doesnt gave any kind of clue regarding this issue. Thanks for sharing – Swapnil Sawant Nov 27 '15 at 14:28
  • Thank you! I have run into this issue in the past, and I ran into it again just now. Thanks for refreshing my memory. Fool me twice... – ganta Nov 28 '18 at 19:27
2
def criteria = Msg.createCriteria()
results = criteria.list{
    user{
        eq("organisation", organisationInstance)
    }
}
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80