Duplicate Class/Entity Mapping Error

nhibernate

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.

Best Answer

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

Hope it will help.