Hello,
I am starting to use NHibernate for a migration, I need to get the data from some stored procedures, processed and then persist it to denormalized tables.
I decided to create an object reflecting the structure of the denormalized table, and then use a named query to fetch the objects having partial data into memory, process the data to complete the object and then use NHibernate to save it to the DB.
The problem I have is that apparently NHibernate does not like to fetch partial data from named SQL queries, I get an IndexOutOfRangeException while calling the method List() the stored procedure executes correctly, and the program works if I remove the InstrumentGuid mapping from the class declaration.
I will like to know if there is a way to tell NHibernate to ignore certain columns when fetching from a SQL query and/or to assign default values to those fields.
I need the complete mapping in the class because I want those fields to be persisted later, but I need to fetch incomplete data first.
I was thinking to have two different classes with a copy constructor but I will prefer to avoid that if possible, any suggestions are welcome.
Hibernate version: 2.0.1 GA
Mapping documents:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Implementation.DataFlattener" assembly="Implementation.DataFlattener">
<class name="Implementation.DataFlattener.FlatPriceWeekly" table="[dbo].[tPRICE_BI_InstrumentPRICEWeekly]">
<id name="ID" type="integer" unsaved-value="0" >
<generator class="assigned" />
</id>
<property name="PriceSeriesGuid" column="PriceSeriesGUID" type="System.Guid" />
<property name="AsOfDateEOW" column="AsOfDateEOW" type="System.DateTime" />
<property name="InstrumentGuid" column="InstrumentGUID" type="System.Guid" />
<property name="PriceGuid" column="PriceGUID" type="System.Guid" />
<property name="AsOfDate" column="AsOfDate" type="System.DateTime"/>
<property name="Currency" column="Currency" type="string" length="3" />
</class>
<sql-query name="getInstrumentPricesWeekly">
<return class="Implementation.DataFlattener.FlatPriceWeekly">
<return-property name="ID" column="ID" />
<return-property name="PriceSeriesGuid" column="ParentGuid" />
<return-property name="AsOfDateEOW" column="AsOfDate" />
<return-property name="PriceGuid" column="Guid" />
<return-property name="InputTypeID" column="InputTypeID" />
<return-property name="InputType" column="InputType" />
<return-property name="QualityID" column="QualityID" />
<return-property name="AsOfDate" column="AsOfDate" />
<return-property name="Currency" column="Currency" />
</return>
EXEC [dbo].[pc_GetPrice] 1, 0, :seriesGuid, 'W', 4, 1, 1
</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: MS SQL 2000
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
|