java - HQL加入: Retrieve Object based on 2 joins (Path expected for join!)

标签 java xml hibernate join

我正在尝试连接 3 个对象并遇到问题。这是我的想法。在Java中,我试图获取某个对象的列表:

List<TypeX> typeXList =
    session.createQuery(
        "from X as x " +
        "join Y as y " +
        "where y.z in (:zList)")
    .setParameterList(":zList", zList)
    .list();

zlist 很小并且是在代码中动态生成的,因此它不应该成为问题。

现在我收到此错误:

ERROR 23-05 11:06:41,566 -Servlet.service() for servlet myServlet threw exception
    org.hibernate.hql.ast.QuerySyntaxException: Path expected for join! [from X as x join Y as y where y.z in (:zList)]
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
    at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
    at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:258)

但是我认为这些已映射,在我的 xml 配置中

<class name="X" table="x">
    <cache usage="read-write"/>
    <id name="id" column="id">
        <generator class="native"/>
    </id>
    <property name="yId" column="y_id"/>
    <many-to-one name="y" column="y_id"
        insert="false" update="false" class="Y" lazy="proxy"/>
    <!-- I need both of these for other reasons, existing code etc -->
    ...
</class>

现在Y类

<class name="Y" table="y">
    <cache usage="read-write"/>
    <id name="id" column="id">
        <generator class="native"/>
    </id>
    <many-to-one name="z" column="z_id" class="Z" lazy="false"/>
    ...
</class>

和Z

<class name="Z" table="z">
    <cache usage="read-write"/>
    <id name="id" column="z_id">
        <generator class="native"/>
    </id>
    ...
</class>

我认为这些足以根据 Z 列表检索 X。我做错了什么?

最佳答案

我认为它一定是加入X.y其中

关于java - HQL加入: Retrieve Object based on 2 joins (Path expected for join!),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23836961/

相关文章:

java - 将 JSON 转换为 XML 时添加额外的元数据

hibernate - 为 UUID 配置 Grails/Hibernate/Postgres

java - C# 相当于 java Class<E> 和 E extends Enum<E>

java - Android:如何使用 Robolectric 运行 PIT 突变测试?

Java 8替代字符串中奇数位置的字符总和?

Iphone XML文件解析偏好,但什么是Big什么是Small?

java - Android 按钮导航与 onclick 监听器

JavaScript 和 XML Dom - 嵌套循环

java - 接收具有相同参数的整数或整数列表

java - 如何在Hsql中进行外连接