hibernate左边连接多个where条件

时间:2013-12-03 09:13:39

标签: java sql hibernate hql

------我正在编写sql查询,其工作正常------------------

SELECT SUM (lb.QUANTITY*mp.DB_PRICE) 
FROM ledger_balance lb 
LEFT JOIN material_price mp ON (mp.MATERIAL_ID = lb.MATERIAL_ID) 
WHERE lb.QTY_TYPE ='G' 
AND lb.BALANCE_TYPE='CUMU' 
AND lb.CUSTOMER_ID = 13
AND mp.CUSTOMER_ID = 13 AND  lb.MATERIAL_ID IN (226, 230, 362, 365)
AND mp.MATERIAL_ID IN (226, 230, 362, 365);

--- hibernate查询它不工作------

SELECT SUM (B.quantity*P.dbPrice) 
FROM com.efl.efms.data.domain.common.LedgerBalance as B 
LEFT JOIN com.efl.efms.data.domain.material.MaterialPrice as P   
with (B.materialId = P.materialCatalog.materialId)  
WHERE   B.balanceType=:balanceType 
AND B.qtyType=:qtyType and B.customerId in (:customerId) AND P.customer.customerId IN (:customerId)  
AND B.materialId in (:materialPriceId)  
AND P.materialCatalog.materialId in (:materialPriceId) ;

请帮助我休眠左连接,我在左连接时遇到以下错误 hibernate java.lang.illegalstateexception点节点,没有左侧

1 个答案:

答案 0 :(得分:7)

您无法加入与Hibernate的非映射关系。

如果您的查询只返回非结构化数据(在您的情况下是一个数字),我倾向于使用本机查询。

  • 您不必浪费时间将查询翻译成HQL
  • 它运行得更快,因为Hibernate的所有翻译流程都可以 ommitted