Skip to content

Can't override key colum name in JoinedSubClass #42

Open
jagregory opened this Issue Jul 21, 2011 · 6 comments

3 participants

@chester89
Collaborator

On it. Shouldn't be too hard to fix

@chester89
Collaborator

Well, I don't know why, but given the code provided, I can't even get the derived type to be automapped - the ClassMaping I receive from AutoPersistenceModel is null. Need to revisit tomorrow

@chester89
Collaborator

That's really strange - when I created the sample project with the configuration provided, generated sql shows that the problem exists, as described. But in tests I can't reproduce it - at all.

@shiznit013

I spent several hours on this problem yesterday, and thought that I was doing something wrong. It seems that JoinedSubClass ignores whatever column name you supply it. I have a Person class with an Employee subclass. Both classes have an Id property, but the column names underlying them are different (PersonID and EmployeeID). When automapped, the subclass key column is generated as ParentClassName_id (Person_id in my case), disregarding the column name supplied to the override mapping.JoinedSubClass<Employee>("EmployeeID");

Below is a simplified version of my situation:

namespace Domain.Model
{
    public abstract class Entity<T>
    {
        public virtual T Id { get; set; }
    }

    public class Person : Entity<Guid>
    {        
    }

    public class Employee : Person
    {
    }

    public class PersonMappingOverride : IAutoMappingOverride<Person>
    {
    public void Override(AutoMapping<Person> mapping)
    {
        mapping.Id(x => x.Id, "PersonID");
        mapping.JoinedSubClass<Employee>("EmployeeID");
    }
    }
}

Which generates (I stripped out the fluff):

<hibernate-mapping>
  <class name="Person">
    <id name="Id">
      <column name="PersonID" />
      <generator class="guid.comb" />
    </id>
    <joined-subclass name="Employee">
      <key>
        <column name="Person_id" />
      </key>
    </joined-subclass>
  </class>
</hibernate-mapping>

Luckily, our project is setup to use all 3 flavors of mapping, so I can just map them fluently for now.

@chester89
Collaborator

yeah, that situation need proper debugging, from what I understand. Somewhere in there joined subclass isn't honored. There's more - FNH doesn't even generate ClassMapping instance in that case, which is really weird

@shiznit013

If I put an override in the subclass, it does honor those properties in the joined-subclass portion of the mapping file. It just won't honor the key column name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.