Ran*_*aul 4 sql groovy hibernate join hql
我遇到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
Run Code Online (Sandbox Code Playgroud)
当我运行上面的代码时,我得到以下错误
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]
Run Code Online (Sandbox Code Playgroud)
以下是我的包裹实体
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;
}
Run Code Online (Sandbox Code Playgroud)
下面是我的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;
}
Run Code Online (Sandbox Code Playgroud)
我在这篇文章中提到了HQL左连接:期望加入的路径,但是我没有看到任何有关我的HQL连接查询的信息.
这个例外"加入的路径"说:
提供从一个实体到另一个实体的路径.连接由映射定义
所以我们需要:
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'
...
Run Code Online (Sandbox Code Playgroud)
该语句left join TransportFile tf更像是一个SQL ...而不是HQL的情况.
我们的声明必须表达导航:left join lip.transportFile tf- 即加入transportFile与之相关的导航lip.
| 归档时间: |
|
| 查看次数: |
11461 次 |
| 最近记录: |