Grails - createCriteria返回javassist实例而不是特定域

时间:2015-12-03 11:32:02

标签: grails createcriteria

我正在使用以下条件来检索已授予某些角色的所有Person个对象(在PersonService中):

@Transactional(readOnly = true)
List findAllByRoles(authorities) {
    Person.createCriteria().list {
            personRoles {
                role {
                    'in'('authority', authorities)
                }
            }
            order('name', 'asc')
        }.unique(false)
}

我现在遇到的问题是它返回ListPerson__$$__javassist_67个对象而不是Person个对象。

如何更改语句以便检索Person个对象?

编辑:

我需要这个,因为我正在使用我在这里与另一个Person对象列表相关的列表。因为我想在两个列表中的一个上使用removeAll,所以需要包含相同类型的对象,而不是这种情况。

2 个答案:

答案 0 :(得分:1)

equals上实施Person方法,以便能够确定2个实例是否相等,哪个实体可以在代理上运行

答案 1 :(得分:0)

Person__$$__javassist_67对象只是此实例中Person类的代理,最常见的是延迟抓取。我不确定你为什么要在这种情况下得到它。我会尝试明确设置fetchMode

import org.hibernate.FetchMode
...
Person.createCriteria().list {
    fetchMode("personRoles", FetchMode.JOIN)
    fetchMode("role", FetchMode.JOIN)
    personRoles {
        role {
            'in'('authority', authorities)
        }
    }
    order('name', 'asc')
}.unique(false)

您可能不需要第二个fetchMode

相关问题