-->
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.  [ 2 posts ] 
Author Message
 Post subject: Object Graph Doesn't Match Data in Immutable Class (View)
PostPosted: Fri Oct 03, 2008 2:04 pm 
Newbie

Joined: Tue Aug 05, 2008 12:59 pm
Posts: 2
Hey all, only been using NHibernate now for about 6 months, and I can usually read or think my way out of interesting problems but this is one I just can't seem to figure out. Please help…

I have a view that is mapped to an immutable class as defined below. When the HQL query is executed against NHibernate with Ayende's Query Analyzer and when I unit test it, I get the same object repeated the exact number of times I was expecting that should have been unique objects. However the dataset (also posted below) returned by the SQL query is correct. Can anyone tell me why the correct dataset is returned but not hydrated as the correct object graph, or better yet, how do I fix it???

Many thanks in advance,

Adam

Hibernate version: 1.2.1.4000

Mapping documents:
Quote:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="DataTransfer.StructureLevels, Entity" table="vwStructureLevels" mutable="false">
<id name="OrganizationId" column="OrganizationId" type="Int32">
<generator class="native" />
</id>
<property name="StructureId" column="StructureLevelId" type="Int32" />
<property name="StructureNameE" column="NameE" type="String" />
<property name="StructureNameF" column="NameF" type="String" />
<property name="HierarchyLevel" column="HierarchyLevel" type="Int32" />
<property name="MaxPositions" column="MaxPositions" type="Int32" />
<property name="PositionsCreatedToDate" column="PositionIDCount" type="long" />
<property name="GuidelineType" column="StructureType" type="Int32" />
<property name="ReportProfileId" column="ReportProfileId" type="Int32" />
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
const string hql = @"select sl from StructureLevels sl where sl.OrganizationId =:orgId order by sl.HierarchyLevel";
structuresDtoList = session.CreateQuery(hql)
.SetInt32("orgId", organizationId)
.List<StructureLevels>();


Name and version of the database you are using:
SQL 2005

The generated SQL (show_sql=true):
select
structurel0_.OrganizationId as Organiza1_7_, structurel0_.StructureLevelId as Structur2_7_,
structurel0_.NameE as NameE7_,
structurel0_.NameF as NameF7_,
structurel0_.HierarchyLevel as Hierarch5_7_,
structurel0_.MaxPositions as MaxPosit6_7_,
structurel0_.PositionIDCount as Position7_7_,
structurel0_.StructureType as Structur8_7_,
structurel0_.ReportProfileId as ReportPr9_7_
from vwStructureLevels structurel0_
where (structurel0_.OrganizationId=197)
order by structurel0_.HierarchyLevel

The repeatedly returned object:
197 437 CHAIRPERSONS PRESIDENTS 10 0 0 3 (null)

The actual returned dataset:
197 437 CHAIRPERSONS PRESIDENTS 10 0 0 3 (null)
197 439 Corner Brook Corner Brook 30 9999 4 0 548
197 440 Gander Gander 40 9999 3 0 548


Top
 Profile  
 
 Post subject: Solved - Rookie Move...
PostPosted: Fri Oct 03, 2008 5:54 pm 
Newbie

Joined: Tue Aug 05, 2008 12:59 pm
Posts: 2
After getting up and walking away from this, I returned to comb through it again. Turns out I had mapped the Id to the incorrect column. I needed to map to StructureId, not OrganizationId. Looking at the HQL after a head clearing also makes this obvious. Thanks and apologies to anyone who had started applying mental CPU cycles.

Adam


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

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.