Hi!
I'm not sure if this is a bug in NHibernate or if the bug sits in front of the monitor.
I have two classes in a many-to-one-relationship:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
<class name="Domain.Foo, Domain">
<id name="Id" access="nosetter.lowercase-underscore">
<generator class="native" />
</id>
<many-to-one name="Bar" lazy="false"/>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
<class name="Domain.Bar, Domain">
<id name="Id" access="nosetter.lowercase-underscore">
<generator class="native" />
</id>
</class>
</hibernate-mapping>
Code:
public class Foo
{
private long _id = 0;
private Bar _bar;
public long Id
{
get { return _id; }
}
public Bar Bar
{
get { return _bar; }
set { _bar = value; }
}
}
public class Bar
{
private long _id = 0;
public long Id
{
get { return _id; }
}
}
Now I use the same criteria to read the row count and the first ten rows (needed for a Paginator class that takes a Criteria as filter condition):
Code:
[Test]
public void TestCriteria()
{
Bar bar = new Bar();
_session.Save(bar);
Foo foo = new Foo();
foo.Bar = bar;
_session.Save(foo);
ICriteria criteria = _session.CreateCriteria(typeof(Foo));
// row Count
criteria.SetFirstResult(0);
criteria.SetMaxResults(NHibernate.Engine.RowSelection.NoValue);
criteria.SetProjection(NHibernate.Expression.Projections.RowCount());
Assert.AreEqual(1, criteria.UniqueResult<int>());
criteria.SetProjection(null);
// rows
criteria.SetFirstResult(0);
criteria.SetMaxResults(10);
IList<Foo> list = criteria.List<Foo>();
Assert.IsNotNull(list);
Assert.AreEqual(1, list.Count);
}
But Nhibernate raise an NHibernate.ADOException with the Message "Unable to perform find" and an inner exception of type System.ArgumentException with the message (translated from German) "System.Object[] is not a value of Type Domain.Foo and can not be used in this generic collection".
If I read the rows before the row count, it works fine. If I make the Id property of Bar virtual and set default-lazy="true" in Bar.hbm.xml it works fine too.
Any ideas what's going wrong here? I've tested this with 1.2.0-CR2 and the current SVN snapshot of 2.0.0.
Thanks,
Tobias