How to map a composite-id when using interfaces (or how to change the class attribute in the key-many-to-one tag)

Christian Erhardt's Avatar

Christian Erhardt

22 Oct, 2010 01:19 PM via web

Hello,

i'm trying to switch out .hbm mappings to fluent mappings an have a problem with the mapping of composite-ids and the usage of Interfaces

the Class looks at follows:

public class ClassWithCompositeId {
  public virtual IKeyOne KeyOne { get; set; }
  public virtual IKeyTwo KeyTwo { get; set; }
}

our hbm mapping looks like this:

<hibernate-mapping ...>
   <class name="ClassWithCompositeId" table="t_classwithcompositeid">
      <composite-id>      
         <key-many-to-one name="KeyOne" column="colkeyone" class="company.namespace.KeyOneImplementation, BL_Stammdaten" />
         <key-many-to-one name="KeyTwo" column="colkeytwo" class="KeyTwoImplementation" />         
      </composite-id>
</hibernate-mapping>

Please note, that we got interfaces in the Class! Now I'm trying to map this with Fluent nhibernate.

Map {
   public ClassWithCompositeIdMap() {
         CompositeId()
            .KeyReference(x => x.KeyOne, "colkeyone")
            .KeyReference(x => x.KeyTwo, "colkeytwo");
          ...
   }
}

But now Fluent generates the Mapping as follows:

...
 <composite-id mapped="false" unsaved-value="undefined">
      <key-many-to-one name="KeyOne" class="company.namespace.IKeyOne, Interfaces, Version=0.1.4.3379, Culture=neutral, PublicKeyToken=null">
        <column name="colkeyone" />
      </key-many-to-one>
      <key-many-to-one name="KeyTwo" class="company.namespace.IKeyTwo, Interfaces, Version=0.1.4.3379, Culture=neutral, PublicKeyToken=null">
        <column name="colkeytwo" />
      </key-many-to-one>
    </composite-id>
...

The "Class" Attribute points now to the Interface not to the implementation of this interface.

How can I tell Fluent nHibernate to use another class as the attribute value?

Regards

MoJo

  1. Support Staff 2 Posted by Paul Batum on 24 Oct, 2010 04:12 AM

    Paul Batum's Avatar

    This was an oversight on our fluent interface. It was very quick to resolve
    so I've pushed a change to my repository:
    http://github.com/paulbatum/fluent-nhibernate/tree/dev

    <http://github.com/paulbatum/fluent-nhibernate/tree/dev>You would use it
    like so:

       Map {
          public ClassWithCompositeIdMap() {
                CompositeId()
                   .KeyReference(x => x.KeyOne, k =>
    k.Type<KeyOneImplementation>(), "colkeyone")
                   .KeyReference(x => x.KeyTwo, k =>
    k.Type<KeyTwoImplementation>(), "colkeytwo");
                 ...
          }
       }

    It should be in the official trunk before too long.

    On Sat, Oct 23, 2010 at 12:21 AM, Christian Erhardt <
    ***@tenderapp.com<tender%***@tenderapp.com>
    > wrote:

  2. 3 Posted by Christian Erhardt on 24 Oct, 2010 08:33 AM

    Christian Erhardt's Avatar

    Ah, okay! I patched Fluent nHibernate here and added a parameter like you did. I though already that this feature was not yet implemented.
    How do I know that this feature is available in the trunk?

  3. Support Staff 4 Posted by James Gregory on 24 Oct, 2010 10:16 AM

    James Gregory's Avatar

    I periodically merge changes into the master/trunk when Paul tells me to.
    Until I get the go-ahead, you can just build the source from Paul's branch.

    On Sun, Oct 24, 2010 at 9:35 AM, Christian Erhardt <
    ***@tenderapp.com<tender%***@tenderapp.com>
    > wrote:

  4. 5 Posted by Christian Erhardt on 24 Oct, 2010 04:06 PM

    Christian Erhardt's Avatar

    Okay, thank you both very very much!

  5. James Gregory closed this discussion on 05 Nov, 2010 02:04 PM.

  6. Christian Erhardt re-opened this discussion on 31 Dec, 2010 09:39 AM

  7. 6 Posted by Christian Erhardt on 31 Dec, 2010 09:39 AM

    Christian Erhardt's Avatar

    One last question:
    I had to build fluent against nHibernate 3.0.1 because of an bug i ran into. But Pauls change did not make it to the trunk yet. So i had to patch it manually. Can you tell me if this patch makes it to the trunk someday?

    Thank you!

    Christian Erhardt

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What day comes after Monday?