AutoMapping, Conventions, Overrides and Mixing Table-per-class-hierarchy with Table-per-subclass

Devon Lazarus's Avatar

Devon Lazarus

05 May, 2010 05:13 PM via web

Sorry for the long post-- trying to be thorough.

I've been able to produce this mapping file using specific mapping conventions:

<hibernate-mapping ...>
  <class ... name="MyCompany.Core.Domain.Entity" table="Entities">
    <id name="Id" type="System.Int32">
      <column name="EntityId" />
      <generator class="identity" />
    </id>
    <discriminator type="String">
      <column name="EntityType" />
    </discriminator>
    ...
    <subclass name="EavPrototype.Core.Domain.Benchmark" discriminator-value="Benchmark">
      <join table="Benchmarks">
        <key>
          <column name="BenchmarkId" />
        </key>
        ...
      </join>
    </subclass>
    <subclass name="EavPrototype.Core.Domain.TestEntity" discriminator-value="TestEntity">
      ...
    </subclass>
  </class>
</hibernate-mapping>

This follows the specific configuration of NH referenced here:

http://nhforge.org/doc/nh/en/index.html#inheritance-mixing-tableper...

However, I'd rather not implement mapping files for all of my entities and use conventions instead.

I've set up IJoinConvention and ISubclassConventions as appropriate, and I've implemented an IAutoMappingOverride for the Entity class. Unfortunately, it isn't quite working as you see below:

<hibernate-mapping ...>
  <class name="MyCompany.Core.Domain.Entity table="Entities">
    <id name="Id" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="EntityId" />
      <generator class="identity" />
    </id>
    <discriminator type="String">
      <column name="discriminator" />
    </discriminator>
    ...
    <subclass name="EavPrototype.Core.Domain.Benchmark" discriminator-value="Benchmark">
      ...
    </subclass>
    <subclass name="EavPrototype.Core.Domain.TestEntity" discriminator-value="TestEntity">
      ...
    </subclass>
  </class>
</hibernate-mapping>

There are two problems with the file. The first is the column name referenced in the discriminator attribute. The second is the lack of a join attribute for the Benchmark entity.

I should be seeing a different column name for the discriminator based on my override method for Entity:

    public void Override(AutoMapping<Entity> mapping)
    {
        mapping.DiscriminateSubClassesOnColumn("EntityType");
    }

I should be seeing the Join as well based on my override method for Benchmark:

    public void Override(AutoMapping<Benchmark> mapping)
    {
        mapping.Join("Benchmarks", AsSubclassWithJoin());
    }

AsSubclassWithJoin() being a static method in my BenchmarkMappingOverride class.

With regard to my issue with the discriminator column, I noticed this method:

    void IAutoClasslike.DiscriminateSubClassesOnColumn(string column)
    {

    }

in:

http://github.com/jagregory/fluent-nhibernate/blob/master/src/Fluen...

Could that be why I'm not seeing the application of the override in the IAutoMappingOverride implementation for Entity?

And as for the second issue, the lack of the join, I might not be understanding the use of the Join() method in the mapping override implementation, but the JoinPart doesn't seem to be applied.

Basically, why is my override for DiscriminateSubClassesOnColumn not being applied. And why is my Join override not being applied.

Help on the two questions is appreciated. (I can separate into two posts if appropriate.)

-devon

  1. 2 Posted by Devon Lazarus on 06 May, 2010 04:54 PM

    Devon Lazarus's Avatar

    I think this answers my second question regarding using the Join() method in IAutoMappingOverrides:

    http://fluentnhibernate.lighthouseapp.com/projects/33236/tickets/16...

    I should've checked there first, sorry.

  2. Support Staff 3 Posted by James Gregory on 16 May, 2010 05:16 PM

    James Gregory's Avatar

    That issue has now been fixed, you might want to checkout if your problem has been corrected as a result.

  3. 4 Posted by Devon Lazarus on 09 Jun, 2010 05:16 PM

    Devon Lazarus's Avatar

    Hi James,

    I appreciate the effort in fixing the problem. I've had to run so far, so fast, I've left conventions behind in lieu of specific ClassMaps and hbm.xml.

    I will revisit my issues after i complete the current phase of my project.

    Regards,

Comments are currently closed for this discussion. You can start a new one.