These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Fetching different number of columns in a named SQL query.
PostPosted: Thu Nov 20, 2008 9:59 am 
Newbie

Joined: Thu Nov 20, 2008 9:28 am
Posts: 1
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:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.