0

我有两个由连接表连接的实体。当我尝试获取所有关联实体时,这只获取关联的标识,而不是它们的属性值:

User.createCriteria().get {
    eq property, value
    fetchMode 'authorities', FetchMode.JOIN
}

只导致与连接表的连接:

...
left outer join
    search_role_auth_user authoritie2_ 
        on this_.ID=authoritie2_.AUTHORITIES_ID 
...

我怎样才能急切地获取关联实体的数据?

4

1 回答 1

0

假设,

class User{
    static hasMany = [authorities: Authority]
}

class Authority{
    static belongsTo = [user: User]
}

authorities可以按照以下标准急切地获取

User.createCriteria().list {
    eq property, value
    authorities{
       //All authorities for User are eagerly fetched by default
    }
}

注意:
list使用 - 代替是get因为有可能获得多个结果,因为标准是基于id比较而不是属性值构建的。

于 2013-07-09T13:21:55.540 回答