java - Why Hibernate doesn't return anything from the Native Query -
i have application based on hibernate 4.2 , spring boot 1.4. , have specific sql query can not model hql in performant way.
log.debug("request current bids station : code {}, bidtype {}, versionnum {}", code, bidtype, grainproadminproperties.getprice().getcurrentversionnumber()); list<object[]> result = sessionfactory.getcurrentsession().createsqlquery( "select bid.*, tp.price tp_price, tp.price_nds tp_pricends " + "from bid, transportation_price tp, station_location lts, partner part, station stat " + "where " + " bid.is_active = true and" + " bid.archive_date null , " + " part.id = bid.elevator_id , " + " part.station_id = stat.id , " + " lts.region_id = stat.region_id , " + " lts.district_id = stat.district_id , " + " (stat.locality_id null or " + " lts.locality_id = stat.locality_id) , " + " ((cast(tp.station_from_code text) = lts.code , " + " cast(tp.station_to_code text) = cast(:code text)) " + " or " + " (cast(tp.station_to_code text) = lts.code , " + " cast(tp.station_from_code text) = cast(:code text))) , " + " cast(bid.bid_type text) cast(:bidtype text) , " + " cast(tp.version_number int) = cast(:versionnumber int)"). setresulttransformer( new resulttransformer() { @override public object transformtuple(object[] tuple, string[] aliases) { log.warn("transform tuple: {}, aliases {}", tuple, aliases); return null; } @override public list transformlist(list collection) { return collection; } } ). setparameter("code", code). setparameter("versionnumber", grainproadminproperties.getprice().getcurrentversionnumber()). setparameter("bidtype", bidtype). list(); log.debug("result of request: {}", result);
in log file can see:
request current bids station : code 865065, bidtype buy, versionnum 2 hibernate: select bid.*, tp.price tp_price, tp.price_nds tp_pricends bid, transportation_price tp, station_location lts, partner part, station stat bid.is_active = true , bid.archive_date null , part.id = bid.elevator_id , part.station_id = stat.id , lts.region_id = stat.region_id , lts.district_id = stat.district_id , (stat.locality_id null or lts.locality_id = stat.locality_id) , ((cast(tp.station_from_code text) = lts.code , cast(tp.station_to_code text) = cast(? text)) or (cast(tp.station_to_code text) = lts.code , cast(tp.station_from_code text) = cast(? text))) , cast(bid.bid_type text) cast(? text) , cast(tp.version_number int) = cast(? int) result of request: []
so returned result empty. i'm trying execute absolutely same request directly in db same parameters , i'm getting 3 results.
could please predict why case?
the problem (as @gaƫlmarziou said) in binding. i'm using enum bidtype input parameter query not transformed string using standard tostring method.
Comments
Post a Comment