max wrote:
no matter if you have maps or pojos you need to have an entity mapped.
If sql-query doesnt work with that then its a bug...it should probably work (but i dont have a concrete test for it)
thanks max...
just resolved the issue with below mapping --
this is a different example than the earlier one...
Code:
<class entity-name="custaccresult">
<id
name="accountno"
type="java.lang.Integer"
column="accountno"
unsaved-value="0"
>
<generator class="identity" />
</id>
<property
name="active"
type="java.lang.String"
column="active"
length="1"
/>
<property
name="accountname"
type="java.lang.String"
column="accountname"
length="1"
/>
<property
name="acc_checked"
type="java.lang.String"
column="acc_checked"
length="1"
/>
</class>
<sql-query name="findAllAccountsForCustomer" >
<return entity-name="custaccresult" >
</return>
select a.accountno as accountno, a.accountname as accountname, b.active as active, 1 acc_checked
from Account a, CustomerAccount b
where customerno = :customerno
and a.accountno = b.accountno union select accountno, accountname, null, 0 acc_checked
from Account where accountno not in
(select c.accountno as accountno from Account c, CustomerAccount d
where c.accountno = d.accountno and d.customerno = :customerno)
</sql-query>
only thing that bothers me is for each sql query(like above where
acc_checked is a dummy column) i would need to define a corresponding mapping class.....
wouldnt it be better if hibernate could just return the resultset as is in list of maps fashion? that way there wont be a need to define mapping class every time for complicated sqls...
in above example,
custaccresult is not a physical table... its defined to map resultset-->Map... however, "id" is a reqd element under class.... so the idea of defining an id field for a resultset is kindof confusing.....