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

Syntax Error when retrieving data from database by joining two tables in Hibernate Sql

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 中使用此查询并提供数据时,这是有效的。但是我将其用作休眠查询,它会出现以下错误。

您需要编写查询 Link : 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