Is there a way to separate out the domain objects and mapping files into two separate projects? I would like to create one project called MyCompany.MyProduct.Core that contains my domain model, and another project that is called MyCompany.MYProduct.Data.Oracle that contains my Oracle data mappings. However, when I try to unit test this I get the following error message:
Named query 'GetClients' not found.
Here is my mapping file:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MyCompany.MyProduct.Core"
namespace="MyCompany.MyProduct.Core"
>
<class name="MyCompany.MyProduct.Core.Client" table="MY_CLIENT" lazy="false">
<id name="ClientId" column="ClientId"></id>
<property name="ClientName" column="ClientName" />
<loader query-ref="GetClients"/>
</class>
<sql-query name="GetClients" callable="true">
<return class="Client" />
call procedure MyPackage.GetClients(:int_SummitGroupId)
</sql-query>
</hibernate-mapping>
Here is my unit test:
try
{
var cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly( typeof( Client ).Assembly );
ISessionFactory sessionFactory = cfg.BuildSessionFactory();
IStatelessSession session = sessionFactory.OpenStatelessSession();
IQuery query = session.GetNamedQuery( "GetClients" );
query.SetParameter( "int_SummitGroupId", 3173 );
IList<Client> clients = query.List<Client>();
Assert.AreNotEqual( 0, clients.Count );
}
catch( Exception ex )
{
throw ex;
}
I think I may be improperly referencing the assembly, because if I do put the domain model object in the MyComapny.MyProduct.Data.Oracle class it works. Only when I separate out in to two projects do I run into this problem.