Hi,
We have just upgraded from Hibernate 3.3 to Hibernate 3.6 (actually as part of upgrading JBoss AS but I don't think this matters in this case), and at least one of our HQL queries are now generating different SQL - which is unfortunately returning different results. I've not had much luck trying to figure out what the problem is, or if this is expected and perhaps we have a problem with our HQL or mapping.
The relevant (to me, please let me know if I've left something out that may be significant) two entities are mapped as a unidirectional one-to-one relationship (using a <many-to-one> element), but I'm including the mapping for TradeApprovals as a reference only, we set the Trade id in it manually.
This is the Trade side mapping:
Code:
<hibernate-mapping>
<class name="foo.bar.Trade"
table="TRADES"
lazy="true"
batch-size="128">
<many-to-one lazy="false"
name="latestApproval"
class="foo.bar.TradeApproval"
cascade="none"
column="LATESTAPPROVALID"
outer-join="true"
fetch="select"/>
<!-- all other stuff removed for clarity -->
</class>
</hibernate-mapping>
And the TradeApprovals side:
Code:
<hibernate-mapping>
<class name="foo.bar.TradeApproval"
table="TRADEAPPROVALS">
<property name="tradeId"
type="long"
update="true"
insert="true"
column="TRADEID"
not-null="true"/>
<!-- all other stuff removed for clarity -->
</class>
</hibernate-mapping>
The HQL query we run is:
Code:
from com.kiodex.model.trade.Trade t left join fetch t.latestApproval where (t.latestApproval is null or t.latestApproval.status <> 7) and t.trader.organization.id = :organizationId and t.deleted = :deleted
In Hibernate 3.3 the HQL query above causes this SQL query to be run:
Code:
select ...
from TRADES trade0_
left outer join TRADEAPPROVALS tradeappro1_ on trade0_.LATESTAPPROVALID=tradeappro1_.ID, PRINCIPALS user3_
where trade0_.TRADERID=user3_.ID
and (trade0_.LATESTAPPROVALID is null or tradeappro1_.STATUS<>7)
and user3_.ORGANIZATIONID=?
and trade0_.TRADEDATE>=?
and trade0_.DELETED=?
Unfortunately, using Hibernate 3.6 this SQL is generated:
Code:
select ...
from TRADES trade0_
left outer join TRADEAPPROVALS tradeappro1_ on trade0_.LATESTAPPROVALID=tradeappro1_.ID, TRADEAPPROVALS tradeappro2_, PRINCIPALS user3_
where trade0_.LATESTAPPROVALID=tradeappro2_.ID
and trade0_.TRADERID=user3_.ID
and (trade0_.LATESTAPPROVALID is null or tradeappro2_.STATUS<>7)
and user3_.ORGANIZATIONID=?
and trade0_.TRADEDATE>=?
and trade0_.DELETED=?
As you can see there is now a second reference to the TRADEAPPROVALS table, and the extra "trade0_.LATESTAPPROVALID=tradeappro2_.ID" has been added to the "where" clause, effectively turning this "
left outer join" statement into an "
inner join" statement.
Does anybody have any thoughts on if this is a new Hibernate bug, or if it is expected considering my mapping and HQL used, and in that case how I can change them to ensure that I get back to the old intent and results?
Regards,