Hi,
I have the problem with HQL select command
getHibernateTemplate().find("select.....")
I have the main select with 2 tables tender and tender_bid (conected by id columns) and in the where condition is sub-select with the same table as in main select (tender_bid).
the problem is, main-select and sub-select has the same alias for tender_bid table.
HQL command:
Code:
return getHibernateTemplate().find("select new
com.freightservice.model.TenderCarrierBestBidInformationResultItem(" +
"tender, tenderBid) " +
"from Tender tender, TenderBid tenderBid " +
"where tender = tenderBid.tender " +
"and tenderBid.carrier = ? " +
"and tenderBid.bidPrice = (" +
"select min(b.bidPrice) " +
"from tenderBid b " +
"where b.carrier = tenderBid.carrier " +
"and b.tender = tenderBid.tender)", carrier);
generated SQL command:
Code:
select
tender0_.id as col_0_0_,
tenderbid1_.id as col_1_0_
from
tender tender0_,
tender_bid tenderbid1_
where
tender0_.id=tenderbid1_.fk_tender_id
and tenderbid1_.fk_carrier_id=?
and tenderbid1_.bid_price=(
select
min(tenderbid1_.bid_price)
from
tender_bid tenderbid1_
where
tenderbid1_.fk_carrier_id=tenderbid1_.fk_carrier_id
and tenderbid1_.fk_tender_id=tenderbid1_.fk_tender_id
)
the problem is, that the first tender_bid and the second (in sub-select) has the same alias tenderbid1_, and generated SQL command is WRONG.
correct SQL command:
Code:
select
tender0_.id as col_0_0_,
tenderbid1_.id as col_1_0_
from
tender tender0_,
tender_bid tenderbid1_
where
tender0_.id=tenderbid1_.fk_tender_id
and tenderbid1_.fk_carrier_id=?
and tenderbid1_.bid_price=(
select
min(tenderbid2_.bid_price)
from
tender_bid tenderbid2_
where
tenderbid2_.fk_carrier_id=tenderbid1_.fk_carrier_id
and tenderbid2_.fk_tender_id=tenderbid1_.fk_tender_id
)
thanks
Ivan