I have a SQL query that returns several columns, i.e.
instead of
Code:
from com.business.sem.Statistics where ...
I have
Code:
select column1, column2 from Table.
When I specify <sql-query name..><return class="myValueObject">,
Hibernate complains that there's noi persistent entity called myValueObject. As a result, query.list() always returns empty collection.
What I want is:
1. ideally, I'd like Hibernate to generate value object for me based on the column names in the SQL query.
2. if that is not possible, I will provide a Java Bean with properties matching column names in the SELECT, and I'd like Hibernate to use reflection to populate these beans with values when I do query.list()
And I don't want to create <class>-style mapping for these value objects because they are read-only.
Is that possible? If not, what's the best solution to wrap columns in SELECT statement into objects?
Hibernate version: 3.0.5
Mapping documents:Code:
<sql-query name="com.business.sem.Statistics.report.for.accountId_dates" cacheable="true" >
<return alias="StatsReportObject" class="com.business.sem.StatsReportRow" />
<![CDATA[
SELECT
C.id AS {StatsReportObject.campaignId},
C.vendorIdString AS {StatsReportObject.campaignVID},
C.name AS {StatsReportObject.campaignName},
AG.id AS {StatsReportObject.adGroupId},
AG.vendorIdString AS {StatsReportObject.adGroupVID},
AG.name AS {StatsReportObject.adGroupName},
K.searchString AS {StatsReportObject.searchString},
S.* AS {StatsReportObject.*},
FROM
KeywordStats S
JOIN VendorKeyword VK ON VK.id = S.vendorKeywordId
JOIN AdGroup AG ON AG.id = VK.adGroupId
JOIN Campaign C ON C.id = AG.campaignId
JOIN VendorAccount VA ON VA.id = C.vendorAccountId
WHERE VK.status = AG.status
AND AG.status = C.status
AND C.status = 'A'
AND VA.id = ?
AND S.startDate >= ?
AND S.endDate <= ?
]]>
</sql-query>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
SQLServer 2000
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: