I'm working on a Grails project using Hibernate (GORM). I have the following Domain Models
ClientContact{
static hasMany = [owners: Person]
static belongsTo = [Person]
}
Person{
static hasMany = [clientContacts:ClientContact]
}
When I try to retrieve all the ClientContacts with a specific owner (Person), I'm running into some funny issues. I'm using the following query criteria:
def query = {
owners {
eq("id", Long.parseLong(params.ownerId))
}
}
def criteria = ClientContact.createCriteria()
def results = criteria.list(params, query)
The problem is.... when I iterate through each of my ClientContacts in the results, they only have the one owner -when in fact, most have many other owners. What gives? I know hibernate/GORM uses lazy fetching, but I thought it would fetch all of the other owners on a ClientContact when I tried to access them.
Any thoughts? I would like to continue using the list() function since it provides some nice paging features.
Andrew