According to this blog post 
http://ayende.com/blog/3941/nhibernate-mapping-inheritance

The <subclass> element should be a child of the <class> element for
TablePerHierarchy if I am reading it correctly. However the mapper
below is not doing that:

 <class name="Event" table="myapp_Events" abstract="true">
    <id name="Id" type="Int32">
      <generator class="identity" />
    </id>
    <discriminator column="type" type="String" />
    <many-to-one name="Specimen" />
    <property name="Date" />
    <property name="Created" />
  </class>

  <subclass name="Molt" discriminator-value="Molt" extends="Event" />

  <subclass name="Feeding" discriminator-value="Feeding"
extends="Event">
    <property name="Food" />
  </subclass>


On Sep 9, 12:08 pm, Travis <[email protected]> wrote:
> Any examples of mapping using TablePerHierarchy?
>
> I'm having issues trying to get it up and running. Getting
> NHibernate.MappingException: No persister for [SubClass] exceptions. I
> must be doing something wrong:
>
>        var mapper = new ConventionModelMapper();
>
>         var baseEntityType = typeof(DomainEntity);
>         mapper.IsEntity((t, declared) =>
> baseEntityType.IsAssignableFrom(t) && baseEntityType != t && !
> t.IsInterface);
>         mapper.IsRootEntity((t, declared) =>
> baseEntityType.Equals(t.BaseType));
>
>         mapper.Class<DomainEntity>(map => map.Id(x => x.Id, m =>
> m.Generator(Generators.Identity)));
>
>         mapper.Class<Event>(e => e.Discriminator(map =>
>                                                      {
>
> map.Column("type");
>
> map.Type(NHibernateUtil.String);
>
> map.NotNullable(true);
>                                                      }));
>
>         mapper.Subclass<Molt>(x =>
>                                   {
>                                       x.DiscriminatorValue("Molt");
>                                   });
>
>        mapper.Subclass<Feeding>(x =>
>                                      {
>
> x.DiscriminatorValue("Feeding");
>                                      });
>
>         mapper.BeforeMapClass += (mi, t, map) => map.Table("myapp_" +
> t.Name.MakePlural());
>         mapper.BeforeMapBag += (insp, prop, map) =>
> map.Cascade(Cascade.All);
>
>         return mapper;
>
> More details on 
> SO:http://stackoverflow.com/questions/7351776/nhibernate-conventionmodel...

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to