Hibernate 3.5.2 introduced a bug when it comes to
formula for derived properties. (we have noticed it when we migrated to the latest version from 3.2.3.ga )
We have the following in one of our hbm files.
Code:
<component name="originalAmount" class="com.uprr.app.ama.model.charge.Money">
<property name="value" type="big_decimal" length="11" formula="( SELECT SUM (li.ORGL_BILL_LINE_ITEM_AMT) FROM AMA_BILL_LINE_ITEM li WHERE li.ACCR_BILL_ID = ACCR_BILL_ID)" />
</component>
Hibernate 3.2.3.ga generates the SQL query like a charm (Notice the bold part):
Code:
select this_.ACCR_BILL_ID as ACCR1_30_18_,
this_.ARMS_RCVB_ID as ARMS2_30_18_,
this_.RCVB_BILL_SRC as RCVB3_30_18_,
this_.BILL_NBR as BILL4_30_18_,
this_.BILL_ACCT_NBR as BILL5_30_18_,
this_.EQMT_INIT as EQMT6_30_18_,
this_.EQMT_NBR as EQMT7_30_18_,
this_.BILD_USER_ID as BILD8_30_18_,
this_.BILD_DATE as BILD9_30_18_,
this_.LAST_UPTD_USER_ID as LAST10_30_18_,
this_.LAST_UPTD_DT as LAST11_30_18_,
this_.PROC_ST_ID as PROC12_30_18_,
([b]SELECT SUM(li.ORGL_BILL_LINE_ITEM_AMT)
FROM AMA_BILL_LINE_ITEM li
WHERE li.ACCR_BILL_ID = this_.ACCR_BILL_ID) as formula0_18_[/b],
:
: and so on
However hibernate 3.5.2 seizes to render the SQL properly, it generates the following erroneous query (notice the bolded-italic part ) :
Quote:
select this_.ACCR_BILL_ID as ACCR1_30_18_,
this_.ARMS_RCVB_ID as ARMS2_30_18_,
this_.RCVB_BILL_SRC as RCVB3_30_18_,
this_.BILL_NBR as BILL4_30_18_,
this_.BILL_ACCT_NBR as BILL5_30_18_,
this_.EQMT_INIT as EQMT6_30_18_,
this_.EQMT_NBR as EQMT7_30_18_,
this_.BILD_USER_ID as BILD8_30_18_,
this_.BILD_DATE as BILD9_30_18_,
this_.LAST_UPTD_USER_ID as LAST10_30_18_,
this_.LAST_UPTD_DT as LAST11_30_18_,
this_.PROC_ST_ID as PROC12_30_18_,
(SELECT this_.SUM(li.ORGL_BILL_LINE_ITEM_AMT)
FROM AMA_BILL_LINE_ITEM li
WHERE li.ACCR_BILL_ID = this_.ACCR_BILL_ID) as formula0_18_,
It should not add alias for
Quote:
SUM
Is it a bug in the latest version, or do we have to tweak a bit to make it work ?