For the list: my last note was wrong, I didn’t manage to fix the underlying
issue.
But after having dug into it further, I found this block of code commented
out in the DefaultDeleteEventListener's OnDelete method:
/*
if ( !persister.isMutable() ) {
throw new HibernateException(
"attempted to delete an object of immutable class: " +
MessageHelper.infoString(persister)
);
}*/
As a result, no exception is raised when attempting to delete an immutable
instance, and the deletion does actually occur afterwards as if the instance
were mutable. I looked at the source, and I suspect that this is the same
in both NHib 2.0 and 2.1.
I’ve opened a JIRA case for it – NH-1985.
From: [email protected] [mailto:[email protected]] On Behalf
Of Rémi Després-Smyth
Sent: October 7, 2009 12:37 PM
To: [email protected]
Subject: [nhusers] Re: Why is NHibernate deleting immutable class instance?
Hi.
I've managed to fix the issue, though I don't understand the underlying
problem.
My record creation step in 'CreateRecordInDB()' was not using a transaction
- I was just creating a command to insert a record and fetch the id. When I
added an explicit ADO transaction to commit that insert, the test started
throwing an exception once again.
This doesn't make any sense to me, especially that it worked with an older
version of NHib. If anyone can explain it, I'd appreciate a comment.
Regards,
Remi.
From: [email protected] [mailto:[email protected]] On Behalf
Of Rémi Després-Smyth
Sent: October 6, 2009 3:03 PM
To: [email protected]
Subject: [nhusers] Why is NHibernate deleting immutable class instance?
Hello.
I'm trying to migrate an app from NHibernate 1.x to 2.1, and I've noticed
something odd: my immutable objects are being deleted in my integration
tests.
For example, this test used to pass:
[Test, ExpectedException(typeof(NHibernate.HibernateException))]
public void DeleteExistingInstanceThrows()
{
// Note: NHib transaction is opened/rolled back in test
setup/teardown
m_testRecordId = CreateRecordInDB();
var dao = new NHibFactory().GetTransDao();
var obj = dao.GetById((long)m_testRecordId, false);
dao.Delete(obj);
dao.CommitChanges();
Assert.IsFalse(TestRecordExists(m_testRecordId));
}
The call to CommitChanges should throw, because of trying to delete an
instance whose type is mapped with mutable="false". However, after updating
the expected exception type, this test now fails (because no exception is
thrown). I've checked the database and traced through the test, and the
record is created, the instance is loaded, and the record gets deleted again
afterwards.
The class in question is mapped to the same table as another class - it is
more-or-less intended as a read-only view of a subset of that data. Here's
the class mapping:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Sample.Trans, Sample" table="tblTrans" mutable="false">
<id name="Id" column="transId" unsaved-value="0">
<generator class="identity" />
</id>
<property name="Amount" column="amount" type="Decimal" />
<!-- ...a half dozen other mapped fields... -->
</class>
</hibernate-mapping>
I expect I'm missing something basic, but I've been scouring the web for any
reason why the mutable attribute might be ignored, and I've come up empty.
Regards,
Remi.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---