为什么当我在hql中使用连接关键字时,我需要加入Path的连接 [英] why do I get Path expected for join when I use join key word in hql

查看:218
本文介绍了为什么当我在hql中使用连接关键字时,我需要加入Path的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下HQL

String FIND_PRODUCT_CLASS_ID = "SELECT pc.id FROM ProductClass pc"+ 
" JOIN ProductGroup pg ON pc.id = pg.productClassId" +
" JOIN Product p ON pg.id = p.id" +
" JOIN ProductSub ps ON p.id = ps.productId WHERE ps.id =:childProductSubId";

当我在Spring Hibernate环境中运行这个查询时,我得到以下堆栈跟踪。

When I run this query in Spring Hibernate environment, I get the following stack trace.

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join! [SELECT pc.id FROM com.xxx.domain.ProductClass pc JOIN ProductGroup pg ON pc.id = pg.productClassId JOIN Product p ON pg.id = p.id JOIN ProductSub ps ON p.id = ps.productId WHERE ps.id =:childProductSubId]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:91)
at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:109)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:284)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:206)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1800)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:328)
... 146 more


String FIND_PRODUCT_CLASS_ID = "SELECT pc.id FROM ProductClass pc, ProductGroup pg, " +
 " Product p, ProductSub ps where pc.id = pg.productClassId "+
 " and pg.id = p.id and p.id = ps.productId and ps.id =:childProductSubId";

我知道我已经找到解决方案,但我不确定它为什么不起作用在HQL中加入关键词。辛博士能向我解释这件事吗?这与映射有关吗?在我的案例中,对象被映射到Hibernate层。

I know that I have already found the solution but I'm not sure why it doesn't work with join key word in HQL. Can sombody explain this to me please? Is this something to do with the mapping? In my case objects are mapped in Hibernate layer.

推荐答案

我们需要在HQL查询中提供路径。
这是加入的路径异常即将到来。

We need to provide path in HQL query. That's the "Path expected for join" the exception is coming.

更改查询如下所示:请根据使用情况进行编辑

change query something like below: Please edit as per use

String FIND_PRODUCT_CLASS_ID = "SELECT pc.id FROM ProductClass pc"+ 
" JOIN pc.ProductGroup pg " +
" JOIN pg.Product p " +
" JOIN p.ProductSub ps WHERE ps.id =:childProductSubId";'

请参阅

这篇关于为什么当我在hql中使用连接关键字时,我需要加入Path的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆