Why does FluentNhibernate return NullReference for existing row? - nhibernate

I do not get an object from this setup
table SPEC (
Special_Name varchar2 pk
Signal integer
Created_At date)
namespace App
{
public class Strategy
{
public virtual string Id { get; private set; }
public virtual int Signal { get; set; }
public virtual DateTime CreatedAt { get; set; }
}
public class StrategyMap : ClassMap<Strategy>
{
public StrategyMap()
{
this.Table("SPEC");
this.Id(x => x.Id).Column("Special_Name");
Map(x => x.Signal).Column("Signal");
Map(x => x.CreatedAt).Column("Created_At");
}
}
}
namespace App.Tests
{
public class StrategyMapTest
{
private ISessionFactory sessionFactory;
public StrategyMapTest()
{
this.sessionFactory = this.CreateSessionFactory();
}
[Fact]
public void Can_read_from_database()
{
using (var session = this.sessionFactory.OpenSession())
{
var fromDb = session.Get<Strategy>("Foo 1");
Assert.Equal("Foo 1", fromDb.Id);
Assert.Equal("1", fromDb.Signal);
Assert.Equal(new DateTime(2011,1,1), fromDb.CreatedAt);
}
}
private ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(OracleClientConfiguration
.Oracle10
.ConnectionString("connString"))
.Mappings(m => m.FluentMappings
.AddFromAssemblyOf<Strategy>()
.ExportTo(#"C:\logs"))
.BuildSessionFactory();
}
}
}
I get an exception in the first assert. No object is retrieved from the database - it exists.
System.NullReferenceException: Object reference not set to an instance of an object.
My exported mapping looks like this
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="App.Strategy, App, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0af8b89e104ed570" table="SPEC">
<id access="backfield" name="Id" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Special_Name" />
<generator class="assigned" />
</id>
<property name="Signal" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Signal" />
</property>
<property name="CreatedAt" type="System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Created_At" />
</property>
</class>
</hibernate-mapping>

Did you check if any SQL query is sent to the database ? you can see that either by using a profiler on the database or the best way is by using Nhibernate Profiler (commercial but there's a free trial)
If there's no SQL sent then there is some problem with your configuration (thought at first glance it seems ok)
If you do see an SQL query sent, you will probably know what your problem is by looking at it

Related

NHibernate issue : persistent class not known

I have two tables Person and PassportInfo with a structure as given below:
Table Person
(
PersonID uniqueidentifier not null, (PK)
Name varchar(100) not null,
Email varchar(100) not null
)
Table PassportInfo
(
ID int identity(1,1) not null Primary Key,
personID uniqueidentifier null, (FK to PersonID in Person table)
PassportNumber varchar(100) not null
)
Also this is the mapping for Person
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Project" namespace="Project">
<class name="classperson" table="Person" >
<id name="ID" type="System.Guid" column="personID">
<generator class="Guid"/>
</id>
<property name="Name" column="Name" type="System.String" length="100" not-null="true" />
<property name="Email" column="Email" type="System.String" length="100" not-null="true" />
<one-to-one name="classpassportinfo" class="classpassportinfo" constrained="true" />
</class>
</hibernate-mapping>
This is the mapping for PassportInfo
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Project" namespace="Project">
<class name="classpassportinfo" table="PassportInfo" >
<id name="ID" type="System.Int32" column="ID">
<generator class="identity"/>
</id>
<property name="PassportNumber" column="PassportNumber" type="System.String" length="100" not-null="true" />
<one-to-one name="classperson" class="classperson" />
</class>
</hibernate-mapping>
This is the Object Class for Person
namespace Project
{
[Serializable]
public class classperson : Base<System.Guid>
{
private System.String _Name;
private System.String _Email;
private classpassportinfo _classpassportinfo;
public classperson()
{
}
public classperson(System.Guid id)
{
base.ID = id;
}
public virtual System.String Name {
get { return _Name; }
set { _Name = value;}
}
public virtual System.String Email {
get { return _Email; }
set { _Email = value;}
}
public virtual classpassportinfo classpassportinfo {
get { return _classpassportinfo; }
set { _classpassportinfo = value;}
}
}
}
Finally this is the object class for PassportInfo
namespace Project
{
[Serializable]
public class classpassportinfo :Base<Systme.Int32>
{
private System.String _PassportNumber;
private classpassportinfo _classpassportinfo;
public classpassportinfo()
{
}
public classpassportinfo(System.Int32 id)
{
base.ID = id;
}
public virtual System.String PassportNumber {
get { return _PassportNumber; }
set { _PassportNumber = value;}
}
public virtual classperson classperson {
get { return _classperson; }
set { _classperson = value;}
}
}
}
When I execute above code, i am getting and error saying persistent class not known: Project.classpassportinfo. I am new to nhibernate. Any help in this appreciated.
To elaborate and clarify #Fran's comment for anyone else struggling with this problem...
For me, in Visual Studio this issue was resolved by:
Open the solution explorer (Project structure navigator)
Locate the mapping file passportinfo.hbm.xml
Right click and choose properties
Under the advanced tab, make sure "Build Action" is set to "Embedded Resource"
The issue should be resolved now. Good luck

Fluent nHibernate: Unsupported mapping type

I'm setting up a new solution to map against SQL data that has been imported from an Access database. Auto Mappings work fine against the entities I have defined but I need to be able to use the Fluent mapping type to give access to the .NotFound.Ignore extension.
I have used exactly the same syntax in another project (I think!) which works fine. Have I made a schoolboy error to cause the "Unsupported mapping type 'IT.Classes.Entities.Admin'"? Any help is much appreciated.
DDL:
CREATE TABLE [dbo].[Admin](
[ID] [int] NOT NULL,
[primaryEmail] [nvarchar](50) NULL,
[secondaryEmail] [nvarchar](50) NULL,
[highPriorityEmail] [nvarchar](50) NULL,
[MobileEmail] [nvarchar](50) NULL,
[EmailUser] [bit] NOT NULL,
[HelpDeskMessage] [nvarchar](max) NULL
) ON [PRIMARY]
Entity:
namespace IT.Classes.Entities
{
public class Admin
{
public virtual bool EmailUser { get; set; }
public virtual string HelpdeskMessage { get; set; }
public virtual string HighPriorityEmail { get; set; }
public virtual int Id { get; set; }
public virtual string MobileEmail { get; set; }
public virtual string PrimaryEmail { get; set; }
public virtual string SecondaryEmail { get; set; }
}
}
Mapping:
using FluentNHibernate.Mapping;
using IT.Classes.Entities;
namespace IT.Classes.Mappings
{
public sealed class AdminMap : ClassMap<Admin>
{
public AdminMap()
{
this.Id(x => x.Id);
this.Map(x => x.EmailUser);
this.Map(x => x.HelpdeskMessage);
this.Map(x => x.HighPriorityEmail);
this.Map(x => x.MobileEmail);
this.Map(x => x.PrimaryEmail);
this.Map(x => x.SecondaryEmail);
}
}
}
Session Factory:
private static ISessionFactory CreateItHelpdeskSessionFactory()
{
return
Fluently.Configure().Database(
MsSqlConfiguration.MsSql2008.ConnectionString(
ConfigurationManager.ConnectionStrings["ITHelpdesk"].ConnectionString))
.Mappings(m => m.FluentMappings.Add<Admin>())
.Mappings(m => m.FluentMappings.Add<Applications>())
.Mappings(m => m.FluentMappings.Add<Category>())
.Mappings(m => m.FluentMappings.Add<Log>())
.Mappings(m => m.FluentMappings.Add<Multipliers>())
.Mappings(m => m.FluentMappings.Add<Os>())
.Mappings(m => m.FluentMappings.Add<Priority>())
.Mappings(m => m.FluentMappings.Add<Request>())
.Mappings(m => m.FluentMappings.Add<Status>())
.BuildSessionFactory();
}
EDIT
I thought I would export the auto mappings to see if they would highlight a problem in my fluent mappings but they seem to be correct:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="IT.Classes.Entities.Admin, ITClasses, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Admin`">
<id name="Id" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="identity" />
</id>
<property name="EmailUser" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="EmailUser" />
</property>
<property name="HelpdeskMessage" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="HelpdeskMessage" />
</property>
<property name="HighPriorityEmail" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="HighPriorityEmail" />
</property>
<property name="MobileEmail" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="MobileEmail" />
</property>
<property name="PrimaryEmail" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="PrimaryEmail" />
</property>
<property name="SecondaryEmail" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="SecondaryEmail" />
</property>
</class>
</hibernate-mapping>
EDIT 2
Full stack trace. Note potentialreasons = 0.
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> System.InvalidOperationException: Unsupported mapping type 'IT.Classes.Entities.Admin'
at FluentNHibernate.PersistenceModel.Add(Type type) in d:\Builds\FluentNH\src\FluentNHibernate\PersistenceModel.cs:line 152
at FluentNHibernate.Cfg.FluentMappingsContainer.Apply(PersistenceModel model) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentMappingsContainer.cs:line 127
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\MappingConfiguration.cs:line 84
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 252
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 264
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 230
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 235
at ConsoleChecker.Program.CreateItHelpdeskSessionFactory() in E:\code\code_testing\2010\ASPHelpdesks\ConsoleChecker\Program.cs:line 48
at ConsoleChecker.Program.GetRequests() in E:\code\code_testing\2010\ASPHelpdesks\ConsoleChecker\Program.cs:line 40
at ConsoleChecker.Program.Main(String[] args) in E:\code\code_testing\2010\ASPHelpdesks\ConsoleChecker\Program.cs:line 24
In your configuration code, the types mentioned in the Fluent Mappings should be the map classes, not the classes being mapped.
That is, instead of:
return
Fluently.Configure().Database(
MsSqlConfiguration.MsSql2008.ConnectionString(
ConfigurationManager.ConnectionStrings["ITHelpdesk"].ConnectionString))
.Mappings(m => m.FluentMappings.Add<Admin>())
.Mappings(m => m.FluentMappings.Add<Applications>())
.Mappings(m => m.FluentMappings.Add<Category>())
.Mappings(m => m.FluentMappings.Add<Log>())
.Mappings(m => m.FluentMappings.Add<Multipliers>())
.Mappings(m => m.FluentMappings.Add<Os>())
.Mappings(m => m.FluentMappings.Add<Priority>())
.Mappings(m => m.FluentMappings.Add<Request>())
.Mappings(m => m.FluentMappings.Add<Status>())
.BuildSessionFactory();
You need to say:
return
Fluently.Configure().Database(
MsSqlConfiguration.MsSql2008.ConnectionString(
ConfigurationManager.ConnectionStrings["ITHelpdesk"].ConnectionString))
.Mappings(m => m.FluentMappings.Add<AdminMap>())
.Mappings(m => m.FluentMappings.Add<ApplicationsMap>())
.Mappings(m => m.FluentMappings.Add<CategoryMap>())
.Mappings(m => m.FluentMappings.Add<LogMap>())
.Mappings(m => m.FluentMappings.Add<MultipliersMap>())
.Mappings(m => m.FluentMappings.Add<OsMap>())
.Mappings(m => m.FluentMappings.Add<PriorityMap>())
.Mappings(m => m.FluentMappings.Add<RequestMap>())
.Mappings(m => m.FluentMappings.Add<StatusMap>())
.BuildSessionFactory();
Even better, to avoid having a separate line for every class map, use the .AddFromAssemblyOf<>() method, which uses reflection to add all class maps from a given assembly:
return
Fluently.Configure().Database(
MsSqlConfiguration.MsSql2008.ConnectionString(
ConfigurationManager.ConnectionStrings["ITHelpdesk"].ConnectionString))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<AdminMap>())
.BuildSessionFactory();

How do I override the automapping for a composite Id, one to many relationship with fluent nhibernate?

I'm polling mulitple systems (domains) for security info so I'm dealing domainUsers and their roles. I've got my entities setup as show below, but I'm having trouble setting up the domainUser.HasMany relationship in the AutoMapper override.
You'll notice that I don't have domainUser.DomainUserId and role.RoleId which make this much more simple (no compositeIds.) I've avoided those fields because I've already got a natural composite key and it will be populate when I pull this data from the downstream domain. If I add those artificial keys, I'll have to pre-fetch their values before I call session.Merge(domainUser). I'm trying to avoid doing that.
The entity objects are obvious (I hope) but here is what I've got.
public class DomainUser
{
public virtual int Domain_Id { get; set; }
public virtual string DomainUserLogin { get; set; }
public virtual string EmployeeId { get; set; }
// extra field removed for breviety
public DomainUser()
{
this.Roles = new List<DomainUserRole>();
}
public virtual void AddRole(DomainUserRole role)
{
role.DomainUser = this;
this.Roles.Add(role);
}
// overrides for equals and getHashCode
}
and
public class DomainUserRole
{
public virtual DomainUser DomainUser { get; set; }
public virtual string DataSegment { get; set; } // Some group of data a user has access to, like US or China
public virtual string RoleName { get; set; }
public virtual string RoleDescription { get; set; }
// extra field removed for breviety
// overrides for equals and getHashCode
}
My db schema is pretty simple.
alt text http://lh6.ggpht.com/_MV6QGBD11JE/S3iX2qcP_jI/AAAAAAAAEE0/PGIO07BlCSo/s800/Untitled.gif.jpg
I've got the IAutoMappingOverride classes started like this. But, I'm at a loss of how to setup the hasMany for roles. It keeps giving me
NHibernate.FKUnmatchingColumnsException:
Foreign key (FK20531BE4163641BB:tblDomainUserRoles [DomainUser]))
must have same number of columns as the referenced primary key
(tblDomainUsers [Domain_Id, DomainUserLogin]).
How do I setup that foreign key to use both those fields?
public class DomainUserMap : IAutoMappingOverride<DomainUser>
{
public void Override(AutoMapping<DomainUser> mapping)
{
mapping.CompositeId()
.KeyProperty(user => user.Domain_Id, "Domain_Id")
.KeyProperty(user => user.DomainUserLogin, "DomainUserLogin");
// I"ve tried this.
// mapping.HasMany(x => x.Roles)
// .KeyColumns.Add("Domain_Id")
// .KeyColumns.Add("DomainUserLogin");
// also tried this where I define this FK in DB with both fields.
// mapping.HasMany(x => x.Roles)
// .ForeignKeyConstraintName("FK_tblDomainUserRoles_tblDomainUsers")
}
}
public class DomainUserRoleMap : IAutoMappingOverride<DomainUserRole>
{
public void Override(AutoMapping<DomainUserRole> mapping)
{
mapping.CompositeId()
.KeyReference(role => role.DomainUser)
.KeyProperty(role => role.DataSegment)
.KeyProperty(role => role.RoleName);
}
}
I did endup hand editing the hbm files. It looks like the most recent build on fluent Nhibernate addresses this issue. Here is what my hbm file look like.
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">
<class xmlns="urn:nhibernate-mapping-2.2" name="AAA.Core.Entities.DomainUser, AAA.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`tblDomainUsers`">
<composite-id mapped="false" unsaved-value="undefined">
<key-property name="Domain_Id" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Domain_Id" />
</key-property>
<key-property name="DomainUserLogin" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="DomainUserLogin" />
</key-property>
</composite-id>
... properties hidden for breviety
<bag inverse="true" cascade="all-delete-orphan" lazy="false" name="Roles">
<key>
<column name="Domain_Id" />
<column name="DomainUserLogin" />
</key>
<one-to-many class="AAA.Core.Entities.DomainUserRole, AAA.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bag>
</class>
</hibernate-mapping>
here is the file for roles.
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">
<class xmlns="urn:nhibernate-mapping-2.2" name="AAA.Core.Entities.DomainUserRole, AAA.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`tblDomainUserRoles`">
<composite-id mapped="false" unsaved-value="undefined">
<key-property name="DataSegment" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="DataSegment" />
</key-property>
<key-property name="RoleName" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="RoleName" />
</key-property>
<key-many-to-one name="DomainUser" class="AAA.Core.Entities.DomainUser, AAA.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="Domain_Id" />
<column name="DomainUserLogin" />
</key-many-to-one>
</composite-id>
... properties hidden for breviety
</class>
</hibernate-mapping>

Fluent NHibernate AutoMapping with discriminator

I'm trying to map inheritance with discriminator, but subclasses don't have discriminator value. How to solve it using AutoMappings?
Domain objects are as following:
public abstract class Item : GuidIdentityEntity {
public virtual string Name { get; set; }
}
public class Product : Item {}
public class RawMaterial : Item {}
Configuration looks like:
AssemblyOf<Item>()
.IgnoreBase<GuidIdentityEntity>();
.IncludeBase<Item>();
.Setup(setup => {
setup.DiscriminatorColumn = type => "Discriminator";
setup.IsDiscriminated = type => type == typeof(Item);
setup.SubclassStrategy = type => (type == typeof(Item))
? SubclassStrategy.Subclass
: SubclassStrategy.JoinedSubclass;
});
Outcome of mappings are:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">
<class xmlns="urn:nhibernate-mapping-2.2" name="Solution.Core.Products.Item, Solution.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2e5ef41be3839ad7" table="`Item`">
<id name="Id" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="guid.comb" />
</id>
<discriminator type="String">
<column name="Discriminator" />
</discriminator>
<property name="Name" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Name" />
</property>
<subclass name="Solution.Core.Products.RawMaterial, Solution.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2e5ef41be3839ad7" />
<subclass name="Solution.Core.Products.Product, Solution.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2e5ef41be3839ad7" />
</class>
</hibernate-mapping>
I found that this works:
public class SubclassConvention : ISubclassConvention, ISubclassConventionAcceptance
{
#region IConvention<ISubclassInspector,ISubclassInstance> Members
public void Apply(ISubclassInstance instance)
{
if (instance.Name == typeof(SalesInvoice).AssemblyQualifiedName)
instance.DiscriminatorValue("SAL");
}
#endregion
#region IConventionAcceptance<ISubclassInspector> Members
public void Accept(IAcceptanceCriteria<ISubclassInspector> criteria)
{
criteria.Expect(subclass => Type.GetType(subclass.Name).BaseType == typeof(Invoice));
}
#endregion
}
In this scenario I have SalesInvoice class deriving from Invoice class. The acceptance criteria for subclass is true when current subclass derives from Invoice. Discriminator value is assigned based on type of subclass.
As you can see, I compare types using names. Unfortunately for some reason subclass.EntityType property is null at runtime so I'm unable to compare types directly.

Doubly connected ordered tree mapping using NHibernate

We need to map simple class using NHibernate:
public class CatalogItem
{
private IList<CatalogItem> children = new List<CatalogItem>();
public Guid Id { get; set; }
public string Name { get; set; }
public CatalogItem Parent { get; set; }
public IList<CatalogItem> Children
{
get { return children; }
}
public bool IsRoot { get { return Parent == null; } }
public bool IsLeaf { get { return Children.Count == 0; } }
}
There are a batch of tutorials in the internet on this subject, but none of them cover little nasty detail: we need order to be preserved in Children collection. We've tried following mapping, but it led to strange exeptions thrown by NHibernate ("Non-static method requires a target.").
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Domain.Model" assembly="Domain">
<class name="CatalogItem" lazy="false">
<id name="Id" type="guid">
<generator class="guid" />
</id>
<property name="Name" />
<many-to-one name="Parent" class="CatalogItem" lazy="false" />
<list name="Children" cascade="all">
<key property-ref="Parent"/>
<index column="weight" type="Int32" />
<one-to-many not-found="exception" class="CatalogItem"/>
</list>
</class>
</hibernate-mapping>
Does anyone have any thoughts?
I'm no expert, but <key property-ref=...> looks strange to me in this usage. You should be able to do <key column="ParentID"/>, and NHibernate will automatically use the primary key of the associated class -- itself, in this case.
You may also need to set the list to inverse="true", since the relationship is bidirectional. [See section 6.8 in the docs.]