views:

1451

answers:

2

I'm trying to get NHibernate to work. I've got this class:

mm.k.Domain.Kampagne

(namespace/assembly is mm.k.Domain)

In another Visual Studio project (Assembly mm.k.Infrastructure) I got my Mapping files (in a Mappings directory), my hibernate.cfg.xml and some repositories.

Heres my mapping file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="mm.k.Domain"
                   namespace="mm.k.Domain">

  <class name="Kampagne" table="Kampagner">
    <id name="Id">
      <generator class="identity" />
    </id>
    <property name="Navn" not-null="true" />
    <property name="Logo" />
  </class>

</hibernate-mapping>

When I'm configuring my session, I do this:

_configuration.AddAssembly(typeof(mm.k.Domain.Kampagne).Assembly);

And thats what doesn't work! When calling:

var test = session.Get<Kampagne>(kampagneId);

I get the following error: "No persister for: mm.k.Domain.Kampagne" Like it doesn't register the embedded mapping fild. Note that I have the build action on the mapping file set to Embedded Resource.

If I change the above line to:

_configuration.AddFile(@"fullpath\mm.k.Infrastructure\Mappings\Kampagne.hbm.xml");

Everything works perfectly fine!

Any ideas? Thanks in advance.

+1  A: 

Not sure what your nhibernate.cfg.xml file looks like, but I generally have an item like this

<mapping assembly="mm.K.Infrastructure"/>

based on your information you've given. NHibernate uses this to load the mapping files from this specific assembly.

This should give you the mapping you need.

ShaneB
That did the trick. Thank you! Strangethat the NHibernate getting started tutorial doesn't mention this?
Tommy Jakobsen
+1  A: 

In case someone will have this issue with Hibernate.NET as I did. Make sure you selected in Properties Window for your file Build Action as "Embedded Resource".

Jenea