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