语法通过在Hibernate Sql中连接两个表从数据库中检索数据时出错

时间:2017-07-17 05:02:22

标签: java mysql hibernate navicat

String query ="From transaction JOIN outlet transaction.outlet_ref_id = outlet.outletid WHERE(transaction.added_date_time between'"+sdate+"' and '"+edate+"') and (outlet.merchant ="+merchantId+")";

这是我用来从数据库中检索数据的查询。当我在Navicat中使用此查询并提供数据时,这是有效的。但我使用它作为hibernate查询它会产生以下错误。

enter image description here

1 个答案:

答案 0 :(得分:1)

您需要编写查询链接:from Company as comp inner join comp.employees as empCompany as comp表示entityName as referenceName

From Transaction t JOIN Outlet o t.outlet_ref_id = o.outletid WHERE(t.added_date_time between'"+sdate+"' and '"+edate+"') and (o.merchant ="+merchantId+")

Transaction

上使用实体名称

更多参考:

http://www.concretepage.com/hibernate/hibernate-hql-associations-and-inner-join-left-outer-join-right-outer-join-cross-join-example

https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html

http://levelup.lishman.com/hibernate/hql/joins.php