2017-07-17 65 views
-1
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查詢,它給出了以下錯誤。語法在通過在休眠Sql中連接兩個表從數據庫檢索數據時出錯

enter image description here

回答

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

+0

我公頃已經試過這一個...它也得到了同樣的錯誤....? – Toshan

+0

請分享你的'transaction'和'outlet'實體代碼,並在你正在執行的Query中共享java代碼 – Sharma