我将相当复杂的SQL查询转换为JPQL。突然之间,我发现因为我在2.0之前的OPENJPA 1.2.8的版本,ON-Clause不起作用。所以,很可能我不能使用Left Open Join。在这种情况下,什么是最好的策略?
JPQL查询:
select priceListTerm.SELLING_PRICE, priceListTerm.COMMISSION_FORMAT, priceListTerm.COMMISSION,
priceListAssignment.EFF_START_DATE, priceListAssignment.EFF_END_DATE,
priceListAssignment.PRIORITY_LEVEL,
venue.CODE, tb.HEADQUARTERS, vendor.NAME from PriceListTerm priceListTerm
JOIN PriceList priceList on priceListTerm.PRICELIST_UID = priceList.UIDPK
JOIN ProductSku productsku on priceListTerm.PRODUCTSKU_UID=productsku.UIDPK
LEFT OUTER JOIN
(PriceListAssignment priceListAssignment JOIN Venue venue on
priceListAssignment.VENUE_UID=venue.UIDPK
JOIN Vendor vendor on vendor.UIDPK=venue.VENDOR_UID)
on priceListAssignment.PRICELIST_UID = priceList.uidpk
where productsku.skuCode= :sku
and (vendor.name is null or vendor.name= :vendor)
order by priceListAssignment.PRIORITY_LEVEL;
答案 0 :(得分:0)
我最终使用了原生查询。所以有效的代码块如下:
...........
query = entityManager.createNativeQuery(GET_LOGICAL_SQL);
List<Object[]> list = query.setParameter(1, skuCode).setParameter(2, vendorName).getResultList();
for (Object[] objects : list){
BigDecimal sellingPrice = (BigDecimal)objects[0];
...........