小编典典

Hibernate 4.3.6 QuerySyntaxException:预期加入的路径

hibernate

HQL连接查询有问题。谁能告诉我我的下面加入HQL查询有什么问题?我正在使用Hibernate 4.3.6,JDK 7和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

我在上面的代码中运行时遇到以下错误

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]

以下是我的包裹实体

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;
}

以下是我的TransportFile实体

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;
}

我参考了这篇文章HQL左联接:联接所需的路径,但是我的HQL联接查询没有任何磨损。


阅读 267

收藏
2020-06-20

共1个答案

小编典典

此异常 “预期加入的路径” 表示:

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

因此,我们需要:

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'
   ...

该语句left join TransportFile tf更像是SQL …对于HQL而言并非如此。

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

2020-06-20