Hibernate version: 1.2.0.Alpha1
Name and version of the database you are using: SQLServer 2000
Mapping
Code:
<class name="CDS.HEPS.DocumentLibrary.Document, CDS.HEPS.DocumentLibrary" table="`Library Item`" >
<id name="Id" column="ItemId" unsaved-value="0" >
<generator class="identity" />
</id>
<property name="Title" />
<property name="CommentsRecipient" />
<property name="Summary" />
<property name="PublishedDate" />
<many-to-one name="State" column="StateId" />
<set name="Categories" table="LibraryItemCategory" fetch="join" >
<key column="ItemId"/>
<many-to-many column="CategoryId" class="CDS.HEPS.DocumentLibrary.Category, CDS.HEPS.DocumentLibrary" />
</set>
<component name="ReviewPanel">
<set name="Users" table="`Library Item Reviewer`" fetch="join" >
<key column="ItemId"/>
<many-to-many column="Id" class="CDS.HEPS.DocumentLibrary.ExtranetUser, CDS.HEPS.DocumentLibrary" />
</set>
<set name="Groups" table="`LibraryItemReviewGroup`" fetch="join" >
<key column="ItemId"/>
<many-to-many column="ExtranetGroupId" class="CDS.HEPS.DocumentLibrary.ExtranetGroup, CDS.HEPS.DocumentLibrary" />
</set>
</component>
<component name="ReviewSchedule">
<set name="Items" >
<key column="ItemId" />
<one-to-many class="CDS.HEPS.DocumentLibrary.ReviewScheduleItem, CDS.HEPS.DocumentLibrary" />
</set>
</component>
<set name="Files" fetch="join" lazy="false" >
<key column="ItemId"/>
<one-to-many class="CDS.HEPS.DocumentLibrary.File, CDS.HEPS.DocumentLibrary" />
</set>
</class>
I get duplicate rows when I run:
Code:
session.CreateCriteria(typeof(Document)).AddOrder(Order.Asc("Title")).List()
However, using HQL (as follows) there are no duplicate rows.
Code:
session.CreateQuery ( "from Document Document order by Document.Title" ).List ( ) ;
for some reason, the first case runs the following SQL:
Code:
SELECT this_.ItemId as ItemId1_, this_.StateId as StateId0_1_, this_.Title as Title0_1_, this_.PublishedDate as Publishe5_0_1_,
this_.Summary as Summary0_1_, this_.CommentsRecipient as Comments3_0_1_, categories2_.ItemId as ItemId__3_, categories2_.CategoryId
as CategoryId3_, users3_.ItemId as ItemId__4_, users3_.Id as Id4_, groups4_.ItemId as ItemId__5_, groups4_.ExtranetGroupId as
Extranet2_5_, files5_.ItemId as ItemId__6_, files5_.FileId as FileId6_, files5_.FileId as FileId0_, files5_.Title as Title6_0_,
files5_.Author as Author6_0_, files5_.FileRef as FileRef6_0_, files5_.ContentType as ContentT6_6_0_, files5_.FileSize as FileSize6_0_
FROM [Library Item] this_ left outer join LibraryItemCategory categories2_ on this_.ItemId=categories2_.ItemId left outer join
[Library Item Reviewer] users3_ on this_.ItemId=users3_.ItemId left outer join [LibraryItemReviewGroup] groups4_ on
this_.ItemId=groups4_.ItemId left outer join [File Item] files5_ on this_.ItemId=files5_.ItemId ORDER BY this_.Title asc
and the second case runs the much simpler:
Code:
select document0_.ItemId as ItemId, document0_.StateId as StateId0_, document0_.Title as Title0_, document0_.PublishedDate as
Publishe5_0_, document0_.Summary as Summary0_, document0_.CommentsRecipient as Comments3_0_ from [Library Item] document0_ order by
document0_.Title
the code with the entities and the mappings is a
http://www.box.net/public/sr58o9pvn7.
Thanks for your help