Question

I'm pondering the use of NHibernate on a project that has a database with some degree of planned denormalization (planned by the DBAs). Reading from one set of tables and mapping one column to one property is not a problem. However when updating I'd have to map one property back to the original column in the original table plus update a few copies of that column in the denormalized tables. Is it possible to do this with NHibernate without using stored procedures?

EDIT: Although I tend to agree with NXC's answer, this question is about how to solve the problem with NHibernate as opposed to solving it in the database.

Was it helpful?

Solution

Yes, you can register an event listener inheriting from DefaultSaveOrUpdateEventListener, override OnSaveOrUpdate and update the other entities.

Here are some blog posts about event listeners:

OTHER TIPS

Some thoughts on de-normalised data:

  • Use sparingly; excessive use of denormalised data is known to be a source of maintenance and data quality problems down the track. One J2EE project I was involved in had just 4 denormalised data items in 560 tables - two of those items were search tables.

  • Relying on an application to keep de-normalised data in sync is a known anti-pattern. The generally accepted way to maintain de-normalised data in a transactional system is to use database triggers. Using triggers means that an update from any source (not just your application) will be propogated by the database itself. You would be better off using triggers to maintain the denormalised data unless something specific prevents it.

  • Denormalised data leaves elephant traps for maintenance developers (especially if you don't use DB triggers to maintain the data). Make sure each and every piece of denormalised data is documented.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top