hi
i have following model:
<class name="Person" table="Person" optimistic-lock="version" >
<id name="Id" type="Int32" unsaved-value="0" >
<generator class="native" />
</id>
<!-- plus some properties here -->
</class>
<class name="Event" table="Event" optimistic-lock="version" >
<id name="Id" type="Int32" unsaved-value="0" >
<generator class="native" />
</id>
<!-- plus some properties here -->
</class>
<class name="PersonEventRegistration" table="PersonEventRegistration" optimistic-lock="version" >
<id name="Id" type="Int32" unsaved-value="0" >
<generator class="native" />
</id>
<property name="IsComplete" type="Boolean" not-null="true"/>
<property name="RegistrationDate" type="DateTime" not-null="true"/>
<many-to-one name="Person" class="Person" column="PersonId" foreign-key="FK_PersonEvent_PersonId" cascade="all-delete-orphan" />
<many-to-one name="Event" class="Event" column="EventId" foreign-key="FK_PersonEvent_EventId" cascade="all-delete-orphan"/>
</class>
there are no properties pointing to PersonEventRegistration neither in Person nor in Event.
when i try to delete an entry from PersonEventRegistration, i get following error:
"deleted object would be re-saved by cascade "
the problem is, i don't store this object in any other collection - the delete code looks like this:
public bool UnregisterFromEvent(Person person, Event entry)
{
var registrationEntry = this.session
.CreateCriteria<PersonEventRegistration>()
.Add(Restrictions.Eq("Person", person))
.Add(Restrictions.Eq("Event", entry))
.Add(Restrictions.Eq("IsComplete", false))
.UniqueResult<PersonEventRegistration>();
bool result = false;
if (null != registrationEntry)
{
using (ITransaction tx = this.session.BeginTransaction())
{
this.session.Delete(registrationEntry);
tx.Commit();
result = true;
}
}
return result;
}
what am i doing wrong here?