java - hibernate HQL元素错误

标签 java hibernate hql

我的 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 = ?

关于java - hibernate HQL元素错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1623457/

相关文章:

java - 在单元测试中为 Hibernate 创建 JNDI 上下文

java - "Not supported by BasicDataSource"cloudfoundry tomcat

java - HQL : Getting the primary key of an object

Java ByteArrayInputStream.read 结果保存在字节数组中——保存 ASCII 值

java - 由于 NullPointerException : Attempt to invoke virtual method HashMap on a null object reference 无法启动 Activity

java - 如何初始化公历,日期为 YYYY-MM-DD 格式?

java - 在 Web 应用程序中管理 EntityManagerFactory

java - JSP中的空指针异常

java - Hibernate:无法检索关联的列表

hibernate HQL : Get count of results without actually returning them