1

This SO question explains the save-update option for the cascade attribute in NHibernate as follows:

save-update - when the object is saved/updated, check the associations and save/update any object that requires it (including save/update the associations in many-to-many scenario).

Does it mean that NHibernate keeps track of objects that were modified and need to be updated in the database when an associated object triggers a database operation or that NHibernate simply updates everybody regardless of modifications being made to them?

I'm trying to find out what is the exact meaning of the "requires" word in that sentence.

Thanks!

Community
  • 1
  • 1
Thomas C. G. de Vilhena
  • 13,819
  • 3
  • 50
  • 44

1 Answers1

0

NHibernate always keeps track of modified objects; this is not related to cascade.

requires in this context means basically that transient objects that are referenced will be saved when the referencing object is saved/updated.

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154
  • I've configured NHibernate to show me its SQL output and it indeed behaved as you said when everything was done within a single **Session**, but in my tests NHibernate hasn't kept track of modified objects across **Sessions** and it issued unnecessary SQL Update commands for everybody! – Thomas C. G. de Vilhena May 24 '12 at 23:15
  • Well, of course it doesn't track across sessions. That's not how it's designed to work; the Session is the **Unit of Work**. Reattaching objects to a different session is *supported*, but that's not the ideal workflow. – Diego Mijelshon May 25 '12 at 02:08