I have some stored procedures which I am using to create reports (each SP groups the data into days / weeks / months / years). By means of an examp开发者_如何学编程le, I have created a simple entity "Report" which matches the fields from the SP but an error is thrown saying that an ID (or Composite ID) is required.
How can I define an ID for what is a generated dataset and does not map to an actual table?
The mapping file I have is:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Report, Business" mutable="false" check="none">
<property name="Year" type="int" />
<property name="Week" type="int" />
<property name="Date" type="DateTime" />
<property name="Count" type="int" />
</class>
<sql-query name="spReport">
<return class="Report, Business" lock-mode="read">
<return-property column="Year" name="Year" />
<return-property column="Week" name="Week" />
<return-property column="Date" name="Date" />
<return-property column="Count" name="Count" />
</return>
exec spReport :StartDate, :EndDate
</sql-query>
</hibernate-mapping>
Any help is greatly appreciated.
Thanks.
<class name="Report, Business" mutable="false" check="none">
<composite-id>
<key-property name="Year" type="int" />
<key-property name="Week" type="int" />
<key-property name="Date" type="DateTime" />
<key-property name="Count" type="int" />
</composite-id>
</class>
You'll have to override Equals
and GetHashCode
in Report
.
Personally, I don't like this approach. It's better not to map the class at all and use SetTransformer(Transformers.AliasToBean<Report>())
on the query.
精彩评论