Cognitronic
Cognitronic

Reputation: 1436

NHibernate Mapping Problem - Can I Map Multiple Assemblies?

I have the following mapping file:

    <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Project1.Accounts"
namespace="Project1.Core.Domain">
    <class name="Equipment" table="Equipment">
        <id name="ID" column="ID">
            <generator class="identity"></generator>
        </id>
        <property name="Name" />
        <property name="Description" />
        <property name="AccountID" />
        <property name="EquipmentTypeID" />
        <many-to-one name="Account" class="Project2.Core.Domain.Account, Project2.Core" column="AccountID"/>
        <many-to-one name="EquipmentType" class="Insight.IT.Accounts.Core.Domain.EquipmentType, Insight.IT.Accounts" column="EquipmentTypeID"/>
    </class>

</hibernate-mapping>

I'm getting the following error:

NHibernate.MappingException: An association from the table Equipment refers to an unmapped class: Project2.Domain.Account

Just to be clear - The Account class lives in a different assembly than the Equipment class does. The project that the Account class resides in has it's own hibernate.cfg.xml.

Basically, it looks like i need a way to reference multiple mapping assemblies in the hibernate.cfg.xml file. Is this possible??

Upvotes: 0

Views: 5439

Answers (3)

Cognitronic
Cognitronic

Reputation: 1436

Thanks for the responses. Actually, I ended up doing it a little different. I just removed the tag from the hibernate.cfg and used fully qualified names in the .hbm.xml files. Thanks!!

Upvotes: -1

Mike Valenty
Mike Valenty

Reputation: 8981

You can do it like this:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
        <property name="dialect">...</property>
        <property name="connection.driver_class">...</property>
        ...
        <mapping assembly="MyProject.OtherAssembly"/>
    </session-factory>
</hibernate-configuration>

Upvotes: 3

Frederik Gheysels
Frederik Gheysels

Reputation: 56944

It is possible, you'll just have to indicate this in your mapping file (and it looks like you did this).

Did you add both the assemblies to the NHibernate configuration, before creating the sessionfactory ?

Upvotes: 1

Related Questions