Id Column Name Not Mapping

Jeff Barriault's Avatar

Jeff Barriault

01 Sep, 2010 02:03 PM via web

I have an override class that looks like this:

public class CarrierMap : IAutoMappingOverride<Carrier>
{
    public void Override(AutoMapping<Carrier> mapping)
    {
        mapping.Table("PFS_CARRIERS_011");

        mapping.Id(x => x.Id, "CARRIER_CODE")
            .GeneratedBy.Assigned();

        . . .
    }
}

The generated XML looks like this:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">

<id name="Id" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
  <column name="Id" />
  <generator class="assigned" />
</id>

. . . </hibernate-mapping>

I know the override is working properly because the table name is getting mapped properly. However, the column name for the Id is being mapped as Id and not as CARRIER_CODE as I've specified in the override.

Is this a bug, or am I missing something?

  1. 2 Posted by Jeff Barriault on 03 Sep, 2010 06:27 PM

    Jeff Barriault's Avatar

    I've managed to do some more testing on this. My complete override class looks like this:

    namespace iPFSv2.Data.NHibernateMaps
    {

    public class CarrierMap : IAutoMappingOverride<Carrier>
    {
        public void Override(AutoMapping<Carrier> mapping)
        {
            mapping.Table("PFS_CARRIERS_011");
    
            mapping.Id(x => x.Id, "CARRIER_CODE")
                .GeneratedBy.Assigned();
    
            mapping.OptimisticLock.Version();
    
            mapping.Version(x => x.Version)
                .Column("VERSION")
                .UnsavedValue("negative");
    
            mapping.Map(x => x.Name, "CARRIER_NAME");
            mapping.Map(x => x.Info, "CARRIER_INFO");
    
            mapping.Map(x => x.IsActive, "ACTIVE").CustomType("YesNo");
    
            mapping.Map(x => x.CreatedBy, "OPERATOR_ID").Not.Update();
            mapping.Map(x => x.CreatedOn, "CREATE_DATE").Not.Update().CustomType("Timestamp");
            mapping.Map(x => x.LastModifiedBy, "LAST_MODIFIED_USER");
            mapping.Map(x => x.LastModifiedOn, "LAST_MODIFIED_DATE").CustomType("Timestamp");
        }
    }

    }

    The complete generated mapping file looks like this:

    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">

    <id name="Id" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Id" />
      <generator class="assigned" />
    </id>
    <version name="Version" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" unsaved-value="negative">
      <column name="VERSION" />
    </version>
    <property name="Name" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="CARRIER_NAME" />
    </property>
    <property name="Info" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="CARRIER_INFO" />
    </property>
    <property name="IsActive" type="YesNo">
      <column name="ACTIVE" />
    </property>
    <property name="CreatedBy" update="false" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="OPERATOR_ID" />
    </property>
    <property name="CreatedOn" update="false" type="Timestamp">
      <column name="CREATE_DATE" />
    </property>
    <property name="LastModifiedBy" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="LAST_MODIFIED_USER" />
    </property>
    <property name="LastModifiedOn" type="Timestamp">
      <column name="LAST_MODIFIED_DATE" />
    </property>

    </hibernate-mapping>

    I've even gone as far as adding a specific override to my AutoPersistenceModel generator like this:

        public AutoPersistenceModel Generate()
        {
            return AutoMap.AssemblyOf<Carrier>(new AutomappingConfiguration())
                .Conventions.Setup(GetConventions())
                .IgnoreBase<Entity>()
                .IgnoreBase(typeof(EntityWithTypedId<>))
                .UseOverridesFromAssemblyOf<CarrierMap>()
                .Override<Carrier>(o => o.Id(x => x.Id).Column("CARRIER_CODE"));
        }

    I have no idea why the Id element ends up with name="Id" and column name="Id" instead of CARRIER_CODE as I've specified in the CarrierMap override class AND specifically in my fluent mapping by using Override.

    Anyone see anything wrong with my code, or is this a bug? By the way, my DLL was compiled from the 1.1 version available as a zip file from the download page.

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    Ten divided by two is what?