【问题标题】:Hibernate 4.3.6 QuerySyntaxException: Path expected for joinHibernate 4.3.6 QuerySyntaxException:连接所需的路径
【发布时间】:2014-09-15 02:17:44
【问题描述】:

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 left join: Path expected for join,但我的 HQL 连接查询没有发现任何问题。

【问题讨论】:

    标签: sql hibernate join groovy hql


    【解决方案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 - 即加入与lip相关的transportFile

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-07
      • 1970-01-01
      • 2015-12-18
      • 2019-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多