DuplicateMappingException: Duplicate collection role mapping while adding assemblies

Viewed 162

I'm trying to make many-to-one mapin, but it fails on Adding Assembly of Document with NHibernate.MappingException:

"Could not compile the mapping document: TestForElma.Models.Person.hbm.xml" DuplicateMappingException: Duplicate collection role mapping TestForElma.Models.Person.Documents

public static ISession OpenSession()
        {
            var configuration = new Configuration();
            var configurePath = HttpContext.Current.Server.MapPath(@"~\Models\Nhibernate\nhibernate.cfg.xml");
            configuration.Configure(configurePath);
            configuration.AddAssembly(typeof(Person).Assembly);
            configuration.AddAssembly(typeof(Document).Assembly);
            ISessionFactory sessionFactory = configuration.BuildSessionFactory();
            new SchemaUpdate(configuration).Execute(true, true);
            return sessionFactory.OpenSession();
        }

And here are hbm.xml files

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" assembly="TestForElma" namespace="TestForElma.Models">
  <class name="Document" dynamic-update="true" >
    <cache usage="read-write"/>
    <id name="Id" type="int">
      <generator class="native" />
    </id>
    <property name="Name" />
    <property name="CreationDate" />
    <property name="BinaryData" />
    <many-to-one name="Author" class="Person"
                 column="AuthorId" cascade = "save-update"/>
  </class>
</hibernate-mapping>

And

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" assembly="TestForElma" namespace="TestForElma.Models">
  <class name="Person" dynamic-update="true" >
    <cache usage="read-write"/>
    <id name="Id" type="int">
      <generator class="native" />
    </id>
    <property name="Name" />
    <property name="Password" />
    <bag name="Documents" inverse="true">
      <key column="AuthorId"/>
      <one-to-many class="Document"/>
    </bag>
  </class>
</hibernate-mapping>

And nhibernate.cfg

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">
      NHibernate.Connection.DriverConnectionProvider
    </property>
    <property name="connection.driver_class">
      NHibernate.Driver.SqlClientDriver
    </property>
    <property name="connection.connection_string">
      Server=Local\SQLEXPRESS; database=DbName; Integrated Security=SSPI;
    </property>
    <property name="dialect">
      NHibernate.Dialect.MsSql2008Dialect
    </property>
  </session-factory>
</hibernate-configuration>

It also doesn't create new Tables in Database.

1 Answers

I started to use Fluent Nhibernate and it works.

Related