我正在尝试连接 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/