When I do a simple Criteria based query to load all Accounts in my system, the resulting list contains a null value as the last item in the list (at index 3968).
I've simplified the code I'm using down to this:
Code:
ICriteria c = q.CreateQuery(typeof(Account));
IList<Account> results = c.List<Account>();
I
thought that the list returned from this would never contain nulls - but in this case, a null is returned, and I don't understand why.
Taking the generated SQL and running it manually against the database works, and I don't see anything out of place in the resultset - but, then again, I'm not entirely sure what to look for.
Any help or suggestions on where to look would be greatfully received.
Hibernate version: 1.2.0 GA
Mapping document:The object is pretty standalone, with no outgoing associations. There is one
inbound association, from a person table.
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="RBNZ.RBContacts.Domain"
assembly="RBNZ.RBContacts.Domain"
default-lazy="false">
<class name="Account"
table="accounts"
lazy="false">
<id name="AccountId">
<generator class="identity"/>
</id>
<property name="AccountId" column="AccountId"/>
<property name="Name" column="Account"/>
<property name="Type" column="Type"/>
<property name="Status" column="Status"/>
<property name="Street" column="Street"/>
<property name="City" column="City"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
using (IQueryContext q = mDatabase.NewQueryContext())
{
ICriteria c = q.CreateQuery(typeof(Account));
IList<Account> results = c.List<Account>();
return results;
}
The QueryContext object is a local wrapper that enforces some local conventions. Lots of other queries in our system don't have the problem I'm experiencing here, so I
believe that the problem is elsewhere.
However, here are the relevant bits of it's implementation in case I'm mistaken. The ancestor class (QueryContext) contains nothing NHibernate specific - mostly, it just implements IDisposable.
Code:
public class NHibernateQueryContext : QueryContext
{
public ISession Session
{
get { return mSession; }
}
public NHibernateQueryContext(ISessionFactory aSessionFactory)
: base()
{
mSession = aSessionFactory.OpenSession();
}
protected override void DisposeManaged()
{
mSession.Dispose();
base.DisposeManaged();
}
public override ICriteria CreateQuery(Type aType)
{
return mSession.CreateCriteria(aType);
}
public override ICriteria CreateQuery(NHibernate.Expression.DetachedCriteria aQuery)
{
return aQuery.GetExecutableCriteria(mSession);
}
private ISession mSession;
}
Name and version of the database you are using:Running against MS SQL Server 2005. The same behaviour occurs against both Express and Enterprise editions, though in both cases they're containing the same data (copied from a production system).
The generated SQL (from the Log4Net logfile):Code:
SELECT this_.AccountId as AccountId0_0_,
this_.Account as Account0_0_,
this_.Type as Type0_0_,
this_.Status as Status0_0_,
this_.Street as Street0_0_,
this_.City as City0_0_
FROM accounts this_