Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 使用左外部联接时,hql查询中出现意外标记:ON_Hibernate_Left Join_Hql - Fatal编程技术网

Hibernate 使用左外部联接时,hql查询中出现意外标记:ON

Hibernate 使用左外部联接时,hql查询中出现意外标记:ON,hibernate,left-join,hql,Hibernate,Left Join,Hql,我在hibernate中使用left join,但它引发了一个异常,即意外标记“ON” 我的查询在sql中运行良好,但我希望在hql中使用相同的查询。所以请帮助我克服这个例外 String hql = "SELECT p.posSerialNo, p.posAssignDate,p.posDetails,p.posMake,p.posSoftwareVer,p.merchants ,m.merchantFirstname, m.merchantLastname , m.merchantBusin

我在hibernate中使用left join,但它引发了一个异常,即意外标记“ON” 我的查询在sql中运行良好,但我希望在hql中使用相同的查询。所以请帮助我克服这个例外

String hql = "SELECT p.posSerialNo, p.posAssignDate,p.posDetails,p.posMake,p.posSoftwareVer,p.merchants ,m.merchantFirstname, m.merchantLastname , m.merchantBusinessName FROM PosDevices as p LEFT JOIN Merchants as m ON p.merchants = m.merchantId";

            Query query = session.createQuery(hql);
            System.out.println(query);
            posList1 = query.list();

请参阅。


尝试此操作

Hibernate
将处理您的映射(
Primary key
父项和
FK
子项)

请谅解

使用的HQL

select from Parent as p left outer join p.child  as c
生成的SQL

select parent0_.id as id2_0_, child1_.id as id0_1_, parent0_.childFK as childFK2_0_, parent0_.prop as prop2_0_, child1_.childProp as childProp0_1_ from Parent parent0_ left outer join Child child1_ on parent0_.childFK=child1_.id

你的语法错了
HQL
语法与正常的
SQL
语法完全不同。在谷歌上查一下:)我知道hql和sql之间有语法上的差异,但我并没有从那里得到proepr解决方案,我在这里发布了我的答案。这可能会对您有所帮助。不,这不起作用。我如何比较主键和外键关系?您遇到了什么错误?Hibernate将为您比较主键和外键关系。它将从注释或xml文件中进行检查。
select parent0_.id as id2_0_, child1_.id as id0_1_, parent0_.childFK as childFK2_0_, parent0_.prop as prop2_0_, child1_.childProp as childProp0_1_ from Parent parent0_ left outer join Child child1_ on parent0_.childFK=child1_.id