
NHibernate 2.0 and Cascading Deletes
April 12, 2008The first alpha version of NHibernate 2.0 has been released some time ago. Oren has put a nice overview of the new features and the bugs that are solved for this first drop. In spite the fact that they put the word 'alpha' in the version name, it is actually RTM quality!
One of the great new additions is the on-delete attribute of the key element for mapping collections.:
<set name="Permissions" inverse="true" cascade="save-update">
<key name="Authorization" on-delete="cascade"/>
<one-to-many class="Permission"/>
</set>
This particular feature solves the issue I've had with one-shot deletes on inverse collections (which I described here). Configuring it this way ensures that NHibernate relies on database-level ON CASCADE DELETE foreign key constraints. This implies that when an object with a collection of child objects is deleted, a single DELETE statement is used to remove all children at once instead of individual DELETE statements for each child object (which are called orphans at this point).
There are some things that you have to take into account here. First, this option bypasses NHibernate's optimistic locking strategy for versioned data. Second, make sure that you configure cascade="save-update" instead of cascade="all" to prevent NHibernate from performing delete cascade checks. This is important when lazy loading is enabled for the collection because it prevents that NHibernate loads one-to-many associations into memory.
I'm really excited about this new release. Kudos to the men and women who have put so much effort in building such a wonderful ORM solution!
Till next time
If you and your team want to learn more about how to write maintainable unit tests and get the most out of TDD practices, make sure to have look at our trainings and workshops or checkout the books section. Feel free to reach out at info. @ principal-it .be

Jan Van Ryswyck
Thank you for visiting my blog. I’m a professional software developer since Y2K. A blogger since Y2K+5. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Past organizer of the European Virtual ALT.NET meetings. Thinking and learning about all kinds of technologies since forever.
Comments


Writing Maintainable
Unit Tests
Watch The Videos
Latest articles
-
Avoid Inheritance For Test Classes
January 6, 2021
-
How To Write Unit Tests For Logging
November 11, 2020
-
Prevent Domain Knowledge From Sneaking Into Solitary Tests
September 30, 2020
-
Why Solitary Tests Should Be Easy To Read
September 9, 2020
-
Tales Of TDD - Stressed And Always In A Hurry
August 19, 2020
Tags
- .NET
- ALT.NET
- ASP.NET
- Agile
- Announcement
- Architecture
- Behavior-Driven Development
- C++
- CQRS
- Clojure
- CoffeeScript
- Community
- Concurrent Programming
- Conferences
- Continuous Integration
- Core Skills
- CouchDB
- Database
- Design Patterns
- Domain-Driven Design
- Event Sourcing
- F#
- Fluent Interfaces
- Functional Programming
- Hacking
- Humor
- Java
- JavaScript
- Linux
- Microsoft
- NHibernate
- NoSQL
- Node.js
- Object-Relational Mapping
- Open Source
- Reading
- Ruby
- Software Design
- SourceControl
- Test-Driven Development
- Tools
- Visual Studio
- Web
- Windows
Disclaimer
The opinions expressed on this blog are my own personal opinions. These do NOT represent anyone else’s view on the world in any way whatsoever.
About
Thank you for visiting my website. I’m a professional software developer since Y2K. A blogger since Y2K+5. Author of written words. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Past organizer of the European Virtual ALT.NET meetings. Thinking and learning about all kinds of technologies since forever.
Latest articles
Avoid Inheritance For Test Classes
How To Write Unit Tests For Logging
Prevent Domain Knowledge From Sneaking Into Solitary Tests
Why Solitary Tests Should Be Easy To Read
Contact information
(+32) 496 38 00 82
info @ principal-it .be