Hi all.
I have a very interesting Problem. My Test App consists of two classes, "Directory" and "Datei" (german for File). The
Directory Class contains an IList with holds a collection of
Datei objects.
The corresponding Database looks like this:
Finally, I want to get a List of all
Directory objects which are in the database, for this, i make a criteria query (see the code below).
As you can see, the Directory Table consists of 2 entries, the Datei Table of 5 entries.
When I now get the List of all Directory objects, I get 5 objects - although i would only expect to get two Directory objects since there are only 2 entries in the database...
Thanks for help...
best regards
markus
Hibernate version:
nhibernate 1.0.2
Mapping documents:
Datei.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="NHibTest.Classes" assembly="NHibTest">
<class name="Datei" table="Datei">
<id name="Id" column="Id" type="Int32">
<generator class="identity" />
</id>
</class>
</hibernate-mapping>
Directory.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="NHibTest.Classes" assembly="NHibTest">
<class name="Directory" table="Directory">
<id name="Id" column="Id" type="Int32">
<generator class="identity" />
</id>
<bag name="Files" lazy="false" fetch="join">
<key column="Directory_FK" />
<one-to-many class="Datei" />
</bag>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
ICriteria crit = session.CreateCriteria(typeof(Directory));
IList data = crit.List();
System.Console.WriteLine(data.Count);
Full stack trace of any exception that occurs:
no exception occurs
Name and version of the database you are using:
MsSql Version 2000
The generated SQL (show_sql=true):
NHibernate: SELECT this.Id as Id1_, files1_.Directory_FK as Director2___, files1_.Id as Id__, files1_.Id as Id0_ FROM Directory this left outer join Datei files1_ on this.Id=files1_.Directory_FK WHERE 1=1
Debug level Hibernate log excerpt:
DEBUG