gpt4 book ai didi

sql - hibernate 4.3.6 QuerySyntaxException : Path expected for join

转载 作者:行者123 更新时间:2023-12-04 23:21:18 25 4
gpt4 key购买 nike

HQL 连接查询有问题。谁能告诉我下面的 join 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 连接查询。

最佳答案

这个异常(exception)“预期加入的路径”是说:

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



所以我们需要:
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 - 即加入 transportFilelip 相关.

关于sql - hibernate 4.3.6 QuerySyntaxException : Path expected for join,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25839985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com