4

I have read that this mapping is not possible in NHibernate 3.3:

<class name="Digital" table="DIGITALS">
    <composite-id>
      <key-many-to-one name="Person" class="Person" column="PERSONID" />
      <key-property name="Id" column="ID">
        **<generator class="increment"/>**
      <key-property/>
    </composite-id>
    <property name="Nombre" column="NOMBRE" />

Basically I need a composite-id's property to be calculated automatically by NH.

Maybe exists a technique to get something similar?

Thanks in advance.

vladiastudillo
  • 407
  • 1
  • 10
  • 23

1 Answers1

3

you have to implement it yourself since CompositeIds are always generatedby assigned for NH

class Digital
{
    private static long number = 0;

    private static long NextNumber()
    {
        return Interlocked.Increment(ref number);
    }

    public Digital()
    {
        Id = NextNumber();
    }
}
Firo
  • 30,626
  • 4
  • 55
  • 94
  • Ok, basically I have to calculate the next Id by my own, maybe inside function addDigital()'s entity Person. Thanks a lot @Firo. – vladiastudillo May 04 '12 at 19:11