I guess I found a bug with regard to class hierarchies.
After requesting an object from the database that does exist, but isn't of the requested type, a new request for the right type will fail because its 'non-existance' is stored in the nonExists HashTable.
Hibernate version:
1.2 beta, current svn
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="test"
assembly="test"
auto-import="true"
default-access="field.pascalcase-m-underscore">
<class name="BaseClass" discriminator-value="b">
<id name="ID" column="ID">
<generator class="native" />
</id>
<discriminator type="Char" column="Type"/>
<subclass name="Sub1" discriminator-value="1">
</subclass>
<subclass name="Sub2" discriminator-value="2">
</subclass>
</class>
</hibernate-mapping>
Code:Code:
session.Save(new Sub1());
session.Save(new Sub2());
session.Flush();
session.Clear();
Sub2 s2 = session.Get<Sub2>(1);
//Returns no results, but key is stored in nonExists hashtable
Sub1 s1 = session.Get<Sub1>(1);
//nonExists.Contains(key) is true => s1 = null
//DEBUG NHibernate.Impl.SessionImpl - entity does not exist
session.Clear();
//nonExists is empty again
s1 = session.Get<Sub1>(1);
//s1 is found
I did a quick workaround by disabling the check on nonExists in SessionImpl.cs. A better solution, I guess, would be to fix the GenerateHashCode() and/or Equals() methods of Engine/EntityKey.cs.