org.hibernate.queryexception意外标记,带有[
我们在项目中使用hibernate。我们有一个查询,它需要左外部联接。查询如下:org.hibernate.queryexception意外标记,带有[,hibernate,hql,jpql,Hibernate,Hql,Jpql,我们在项目中使用hibernate。我们有一个查询,它需要左外部联接。查询如下: 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.st
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
如何知道我在编写查询时正在使用JPQL或HQL
我有一个场景,我必须在查询中实现左外连接
所以我用”和左外连接关键字写了“”
但我有以下例外:
org.hibernate.queryexception unexpected token with [
我读到HQL支持with,但JPQL不支持with。因此我有两个问题:
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作为memeber变量。一个好的经验法则通常是,如果您的应用程序正在创建一个
EntityManagerFactory
并且您正在使用EntityManager
发出查询,那么您将创建基于JPQL的查询。如果您的应用程序正在创建一个会话工厂
,并且您正在使用一个会话
来发出查询,那么您通常会提供HQL
也就是说,文档中的JPA 2.1增加了对ON子句中的要求的支持。因此,为了在JPQL中应用这样的条件,您需要编写:
String sql = "SELECT e FROM Employee e LEFT JOIN e.address a ON a.city = :city"
Query<MyEntity> query = entityManager.createQuery( sql, MyEntity.class );
query.setParameter( "city", "New York" );
List<MyEntity> results = query.getResulList();
至少发布您的查询/代码…以便我们知道如何继续。