Hibernate 4.3.6 QuerySyntaxException:加入的路径 [英] Hibernate 4.3.6 QuerySyntaxException: Path expected for join

查看:169
本文介绍了Hibernate 4.3.6 QuerySyntaxException:加入的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HQL连接查询有问题。任何人都可以告诉我什么错我的下面加入HQL查询?
使用Hibernate 4.3.6,JDK 7和Groovy 2.2

  def query ='从Parcel中选择lip.referenceId作为lip left join TransportFile tf其中,lip.statusDisplayName!= tf.statusDisplayName'
def hqlQuery = session.createQuery(query)
def hqlcount = hqlQuery.list()。size

当我运行上面的代码时,我得到下面的错误

  com.dc.core.common.exception.BaseApplicationException:org.hibernate.hql.internal.ast.QuerySyntaxException:加入的路径! [从com.dc.apps.cp.ebilling.model.impl.Parcel中选择lip.referenceId作为lip left join TransportFile tf where lip.statusDisplayName!= tf.statusDisplayName] 

以下是我的Parcel实体

  package com.dc. apps.cp.ebilling.model.impl 
@Entity
@Audited
public class Parcel implements IPersistentEntityInstance {

private static final long serialVersionUID = 1L;
私人长ID;
@AttributeReadPermission(name =SUBMITTEDFILE.READ)
@AttributeWritePermission(name =SUBMITTEDFILE.UPDATE)
private文件submittedFile;
私人ParcelType类型;
private boolean isBeingSubmitted;
private TransportFile transportFile;

$ / code $ / pre

下面是我的TransportFile实体

  package com.dc.apps.cp.legacy.model.impl; 
@Entity
@EntityMetadataDefaults(editable = false)
public class TransportFile implements ITransportObject {

private static final long serialVersionUID = 1L;
私人长ID;
private String statusDisplayName;
// [ReferenceID] [varchar](30)NOT NULL
private String referenceId;
// [发送] [日期时间] NULL,
私人时间戳sentDate;
// [received] [datetime] NULL,
私人时间戳receivedDate;
// [Status] [varchar](4)NULL,
private String statusCode;
私人列表< TransportLog> TransportLogs;
private String rejectReason;
}

我引用这篇文章 HQL left join:预期加入的路径,但我没有看到任何worng我的HQL连接查询。

解决方案

这个例外期望加入的路径说:


提供从一个实体到另一个实体的路径。连接由映射定义


所以我们需要:

 从parcel中选择lip.referenceId 
作为lip
//而不是这个
// left join TransportFile tf
//我们需要一个路径从Parcel到TransportFile
left join lip.transportFile tf
where lip.statusDisplayName!= tf.statusDisplayName'
...

语句 left join TransportFile tf 更像是一个SQL ...对于HQL来说并非如此。 / p>

我们的声明必须表达导航: left join lip.transportFile tf - 即加入 lip 相关的transportFile


Am having problem with HQL join query. Can anyone tell me whats wrong with my below join HQL query? Am using Hibernate 4.3.6, JDK 7 and Groovy 2.2

def query = 'select lip.referenceId from Parcel as lip left join TransportFile tf where lip.statusDisplayName != tf.statusDisplayName'
def hqlQuery = session.createQuery(query)
def hqlcount = hqlQuery.list().size

Am getting the below error when i run above code

com.dc.core.common.exception.BaseApplicationException: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join! [select lip.referenceId from com.dc.apps.cp.ebilling.model.impl.Parcel as lip left join TransportFile tf where lip.statusDisplayName != tf.statusDisplayName]

Below is my Parcel entity

package com.dc.apps.cp.ebilling.model.impl
@Entity
@Audited
public class Parcel implements IPersistentEntityInstance {

private static final long                  serialVersionUID = 1L;
private Long                               id;
@AttributeReadPermission(name = "SUBMITTEDFILE.READ")
@AttributeWritePermission(name = "SUBMITTEDFILE.UPDATE")
private File                               submittedFile;
private ParcelType                  type;
private boolean                            isBeingSubmitted;
private TransportFile              transportFile;
}

Below is my TransportFile entity

package com.dc.apps.cp.legacy.model.impl;
@Entity
@EntityMetadataDefaults(editable = false)
public class TransportFile implements ITransportObject {

private static final long          serialVersionUID = 1L;    
private Long                       id;
private String                     statusDisplayName;    
// [ReferenceID] [varchar](30) NOT NULL
private String                     referenceId;
// [sent] [datetime] NULL,
private Timestamp                  sentDate;
// [received] [datetime] NULL,
private Timestamp                  receivedDate;
// [Status] [varchar](4) NULL,
private String                     statusCode;
private List<TransportLog> TransportLogs;    
private String                     rejectionReason;
}

I refered to this post HQL left join: Path expected for join but I dont see any anything worng my HQL join query.

解决方案

This exception "Path expected for join" is saying:

Provide a path from one entity, to the other. The join is defined by the mapping

So we would need:

select lip.referenceId 
   from Parcel as lip 
   // instead of this
   // left join TransportFile tf 
   // we need a path from Parcel to TransportFile
   left join lip.transportFile tf 
   where lip.statusDisplayName != tf.statusDisplayName'
   ...

The statement left join TransportFile tf is more like a SQL... which is not the case for HQL.

Our statement must be expressing navigation: left join lip.transportFile tf - i.e. join the transportFile which is related to lip.

这篇关于Hibernate 4.3.6 QuerySyntaxException:加入的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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