tags:

views:

1266

answers:

2

I have this domain hierarchy:

User -> EntityWithAuditDate -> Entity

Here is the domain: (simplified)

public class User : EntityWithAuditDate 
{ 

      public User(){} 

      public virtual string Name { get; set; } 

} 


public abstract class EntityWithAuditDate : Entity 
{ 

       public EntityWithAuditDate() { } 


       public virtual DateTime? CreatedAt { get; set; } 
}

And the mapping(simplified):

    <class name="User" table="Users" abstract="false"> 
            <id name="Id" type="Int32" column="UserId"> 
                    <generator class="identity" /> 
            </id> 
            <property name="Name" type="String"/> 
            <property name ="CreatedAt"/> 
    </class>

When I ran a mapping integration unit test, I got this error:

Tests.AltNetTime.Data.NHibernateMaps.MappingIntegrationTests.CanConfirmData­baseMatchesMappings: FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

  • Database was not configured through Database method.

    ----> FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

  • Database was not configured through Database method.

    ----> NHibernate.MappingException : Could not compile the mapping document: (XmlDocument) ----> NHibernate.DuplicateMappingException : Duplicate class/entity mapping AltNetTime.Core.User TearDown : System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. ----> System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary.

The unit test passed if the User class inherits from Entity instead. Also, I had to remove the CreatedAt property from the mapping file. Apparently, there was something wrong with the EntityWithAuditDate class. I am not sure what caused the duplicate class/entity mapping. Any ideas?

Thanks.

+1  A: 

You need to change IsBaseType convension in your project. Additional information you can find here

Hope it will help.

Sly
Thanks for the additional information. I have seen it before. How do I do that on hbm? I am not using Fluent NHibernate here.
Roger
Thanks for your guidance. I have been using Sharp Architecture. By default, it uses Fluent NHibernate. But I ran into an error in its auto-mapping recently. So, I switched to hbm to work around the problem. Since then, I get so used to hbm files that I forgot about the conventions in Fluent NHibernate. You are right. I am missing the IsBaseType convension.
Roger
A: 

Duplicate class/entity mapping is often triggered if you copy&paste your *.hbm files and forget to change the

So in two *.hbm files you have the same value in the name attribute.