0

我正在使用以下标准来检索Person授予特定角色的所有对象(在 中PersonService):

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

我现在遇到的问题是它返回List带有Person__$$__javassist_67对象而不是Person对象。

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

编辑:

我需要这个,因为我正在使用与另一个Person对象列表相关的列表。正如我想removeAll在两个列表之一上使用的那样,两者都需要包含相同类型的对象,但情况并非如此。

4

2 回答 2

1

实现该equals方法Person以能够识别 2 个实例是否相等,这将跨代理工作

于 2015-12-06T15:01:39.177 回答
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.

于 2015-12-03T14:12:07.950 回答