Here is the native sql:
SELECT
DISTINCT ElCustomer.OID,
ElCustomer.LDC_OID,
ElCustomer.ADDR_OID ,
ElCustomer.LDC_CNSMR_ACNT_NUM ,
ElCustomer.FULL_NAME ,
ElCustomer.NAME_VALIDATOR,
ElCustomer.ADDR_VALIDATOR ,
ElCustomer.BILLING_CYCLE,
ElAddr.MINISTRY_OID ,
ElAddr.STREET_ADD ,
ElAddr.UNIT_NUM ,
ElAddr.CITY_OID,
ElAddr.PROVINCE,
ElAddr.POST_CODE,
ElCity.NAME cityName,
ElMinistry.NAME ministryName
FROM
EL_ADDR ElAddr,
EL_CITY ElCity,
EL_CUSTOMER ElCustomer,
EL_MINISTRY ElMinistry,
EL_DAILY_AGG_DATA,
EL_SEARCH_ENTITY searchCity,
EL_SEARCH_ENTITY customerSearch,
EL_SEARCH_ENTITY searchMinistry
WHERE
customerSearch.TYPE = 'C' AND
EL_DAILY_AGG_DATA.SEARCH_ENTITY_OID = customerSearch.OID AND
EL_DAILY_AGG_DATA.SRVC_DAY BETWEEN :startDate AND
:endDate AND
ElCustomer.OID = customerSearch.VALUE AND
searchCity.TYPE ='I' AND
elCity.OID = searchCity.VALUE AND
elCustomer.ADDR_OID = elAddr.OID AND
elAddr.CITY_OID = elCity.OID AND
searchMinistry.TYPE = 'M' AND
elMinistry.OID = searchMinistry.value AND
elAddr.MINISTRY_OID = elMinistry.OID AND
searchMinistry.value = NVL ( :ministryOid , searchMinistry.value ) AND
UPPER( ElAddr.STREET_ADD ) LIKE '%' || NVL ( :street ,UPPER( ElAddr.STREET_ADD ) ) || '%' AND
searchCity.value = NVL ( :city , searchCity.value ) AND
ElAddr.POST_CODE LIKE NVL ( CONCAT(:postcode1,:postcode2) , ElAddr.POST_CODE ) AND
ElCustomer.LDC_CNSMR_ACNT_NUM = NVL ( :consumerAccountNumber , ElCustomer.LDC_CNSMR_ACNT_NUM )
I tried converting this to HQL , but Hiberate disliked the aliased self joins to EL_SEARCH_ENTITY.
tenwit wrote:
But if you're using createSQLQuery then the functionality isn't there. You have to do it yourself. Doesn't matter that it would be easy for hibernate to do it: if noone has put the functionality in, then you can't use that functionality.
Can I re-ask a couple of questions:
1) Have you tried using nvl() in an HQL query? Is it supported? That's probably the way to go, if it's possible.
2) What query are you writing that HQL cannot handle? Why are you using SQL queries, which do not handle the "new" syntax, when you could be using HQL, which does?