views:

275

answers:

0

Hi I've got 2 entities and splitter table for many-to-many relationship:

CREATE TABLE T_CUSTOMER
(
  CUSTOMER_ID NUMBER NOT NULL
)

CREATE TABLE T_CC
(
  CC_ID    NUMBER  NOT NULL
)

CREATE TABLE T_CUSTOMER_CC_SPLITTER
(
  CCCU_CUSTOMER_ID  NUMBER   NOT NULL,
  CCCU_CC_ID        NUMBER   NOT NULL,
  STATUS       NUMBER   NOT NULL
)

I've created mapping for them:

 public CCMap()
        {
            WithTable("T_CC");
            Id(x => x.Id, "CC_ID").GeneratedBy.Sequence("SQ_CC_ID");
}

public CCHistoryMap()
        {
            WithTable("T_CUSTOMER_CC_SPLITTER");
            UseCompositeId()
               .WithKeyReference(x => x.Customer, "CCCU_CUSTOMER_ID")
               .WithKeyReference(x => x.CC, "CCCU_CC_ID");

            Map(x => x.HistoryStatusInt,"CCCU_STATUS").Access.AsCamelCaseField(Prefix.Underscore);
}

public CustomerMap()
        {
            WithTable("T_CUSTOMER");
            Id(x => x.Id, "CUSTOMER_ID").GeneratedBy.Sequence("SQ_CUSTOMER_ID"); ;

            HasMany(x => x.CCHistories).Access.AsCamelCaseField(Prefix.Underscore)
                .WithTableName("T_CUSTOMER_CC_SPLITTER")
                .KeyColumnNames.Add("CUSTOMER_ID")
                .Inverse()
                .Cascade.All();
}

When I try to save customer with new record in CCHistories I get error:

NHibernate.StaleStateException: Unexpected row count: 0; expected: 1

What have I done wrong?