我的HibernateUserImpl映射如下所示

<set name="groups" table="OS_USER_GROUP" inverse="false" cascade="none" lazy="false">
    <key column="user_id"/>
    <many-to-many column="group_id" class="com.opensymphony.user.provider.hibernate3.ahxu.impl.HibernateGroupImpl"/>
</set>


我做HQL查询

select distinct hibuser from HibernateUserImpl hibuser, hibuser.groups.elements  hibgroup where hibuser.name = ? and hibgroup.name = ?


我收到hibuser.groups.elements的错误。我有什么想念的吗?

控制台错误

org.hibernate.hql.ast.QuerySyntaxException: hibuser.groups.elements is not mappe
d [select distinct hibuser from com.opensymphony.user.provider.hibernate3.ahxu.i
mpl.HibernateUserImpl hibuser, hibuser.groups.elements  hibgroup where hibuser.n
ame = ? and hibgroup.name = ?]

最佳答案

我认为您需要进行明确的加入。

    select distinct hibuser
    from HibernateUserImpl hibuser
    join hibuser.groups hibgroup
    where hibuser.name = ? and hibgroup.name = ?

09-13 07:53