本文介绍了我无法在休眠hql查询中的两个表之间建立内部联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此很陌生.请帮助我.

I am new with this. Please help me.

我的内部联接看起来像这样:select p.idprodus, p.denumire, p.cantitate from Produs p inner join Furnizor fon p.idfurn = f.idfurn

My inner join looks like this:select p.idprodus, p.denumire, p.cantitate from Produs p inner join Furnizor fon p.idfurn = f.idfurn

我想在idfurn列上进行内部联接,但是出现以下错误:

I want to make the inner join on the column idfurn, but I get these errors:

org.hibernate.QueryException:必须在外部联接或完全联接之后加上路径表达式select p.idprodus, p.denumire, p.cantitate from sakila.entity.Produs p inner join Furnizor fon p.idfurn = f.idfurn

org.hibernate.QueryException: outer or full join must be followed by path expression select p.idprodus, p.denumire, p.cantitate from sakila.entity.Produs p inner join Furnizor fon p.idfurn = f.idfurn

at org.hibernate.hql.classic.FromParser.token(FromParser.java:170)
at org.hibernate.hql.classic.ClauseParser.token(ClauseParser.java:86)
at org.hibernate.hql.classic.PreprocessingParser.token(PreprocessingParser.java:108)
at org.hibernate.hql.classic.ParserHelper.parse(ParserHelper.java:28)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:216)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:185)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)

推荐答案

在HQL中,您使用实体,而不是表.并且实体通过关联(OneToOne,OneToMany等)链接在一起,可以在关联的实体之间进行联接.

In HQL, you use entities, not tables. And entities are linked together by associations (OneToOne, OneToMany, etc.) Joins can anly be done between associated entities.

例如,如果您在产品"和提供者"之间建立了ManyToOne关联,则HQL查询为:

For example, if you have a ManyToOne association between Product and Provider, the HQL query is:

select p from Product p inner join p.provider provider where ...

on子句是不必要的,因为Hibernate从ManyToOne关联的映射中知道使用product.id_provider外键到provider.id_provider主键的产品与其提供者相关联.

The on clause is unnecessary, because Hibernate knows from the mapping of the ManyToOne association that a Product is associated with its provider using the product.id_provider foreign key to the provider.id_provider primary key.

休眠文档.

这篇关于我无法在休眠hql查询中的两个表之间建立内部联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 03:22