I have a class Country with a corresponding table Country in the database. When I get the countries from the database using NHibernate, I get older values and not the current values of a record in the database. When I change 'England' to 'UK', save the object and call GetAll (see code excerpt below), I still get 'England' instead of 'UK' as expected. I checked in the database and the record has changed. Does NHibernate has some caching going on?
Hibernate version:
0.99.1.0
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="MyApp.Domain">
<class name="Country" table="Country">
<id name="ID" type="Int32" column="id" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="Name" column="name" type="String" length="50" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
public IList GetAll(Type type, params string[] sortProperties)
{
ICriteria crit = session.CreateCriteria(type);
if (sortProperties != null)
{
foreach (string sortProperty in sortProperties)
{
crit.AddOrder(Order.Asc(sortProperty));
}
}
return crit.List();
}
...
IList countries = GetAll(typeof(Country), null);
Name and version of the database you are using:
SQL Server 2005