【发布时间】:2017-07-01 00:22:52
【问题描述】:
我们在项目中使用休眠。我们有一个需要左外连接的查询。查询如下:
如何知道我在编写查询时使用的是 JPQL 还是 HQL。
我有一个场景,我必须在查询中实现左外连接。
所以我写了 'with' 以及左外连接关键字。
但我得到以下异常:
org.hibernate.queryexception unexpected token with [
我读到 HQL 支持 with 但 JPQL 不支持。所以我有两个问题:
1)如何识别我的项目中使用的是JPQL还是HQL以及哪个版本? 2) 如果 JPQL 不支持 'with',那么如何在两个表之间实现具有特定属性值的左外连接。
查询如下:
select v.vId,v.vName,cur.code,con.dxId from
vanTb v, regionTb r, currencyTb cur, connTb con
where
v.vNum = r.vNum
and v.vCode = r.vCode
and v.vId = cur.vId
and v.vId *= con.vId
and con.dlId = 1234 and v.status=1
*= -> sybase ASE 数据库中的左外连接。
命名查询为:
select v.vId,v.vName,cur.code,con.dxId from vanTb v inner join v.regionTb r inner join
v.currencyTb left outer join v.connTb con with con.dlId = :DlId where vendor.status = 1
这里 regionTb、currencyTb 和 connTb 和 vanTb 是实体 bean 的名称, vanTb.java 有 regionTb、currencyTb 和 connTb 作为成员变量。
【问题讨论】:
-
至少发布您的查询/代码...以便我们知道如何继续。