Thanks ffray, your solution worked. Here is what I did:
sql-mapping.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<sql-query name="my-query">
<return class="com.blah.db.domain.Results"/>
select
a.id as data_id, b.name as data_name, c.city as data_city
from
emp a, identity b, address c
where
a.id = b.id and a.id = c.id
</sql-query>
</hibernate-mapping>
Results.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.blah.db.domain.Results" lazy="false">
<composite-id>
<key-property name="data_id"/>
<key-property name="data_name"/>
</composite-id>
<property name="data_city"/>
</class>
</hibernate-mapping>
Include both these mappings in hibernate.cfg.xml
Java code snippet:
Code:
Query q = session.getNamedQuery("my-query");
LOG.info("Running query...");
List data = q.list(); // list of Results
LOG.info("return size: " + data.size());
ofcourse, this is not the real thing, but should be enough to get someone else started on something similar.
Thanks to Cameron too. You book seems good, I have added it to my wish list. (I am not using annotation right now, so did not look into your solution much)
Thanks again
Ajay