1.

Nhibernate Is Deleting My Entire Collection And Recreating It Instead Of Updating The Table?

Answer»

This generally happens when NHibernate can't figure out which items changed in the collection. Common causes are:

  • replacing a persistent collection entirely with a new collection INSTANCE
  • passing NHibernate a manually constructed object and calling Update on it.
  • serializing/deserializing a persistent collection apparently also causes this problem.
  • updating a <BAG&GT; with INVERSE="false" - in this case, NHibernate can't construct SQL to update an INDIVIDUAL collection item.

Thus, to avoid the problem:

  • pass the same collection instance that you got from NHibernate back to it (not necessarily in the same session),
  • try using some other collection instead of <bag> (<idbag> or <set>), or
  • try using inverse="true" attribute for <bag>.

This generally happens when NHibernate can't figure out which items changed in the collection. Common causes are:

Thus, to avoid the problem:



Discussion

No Comment Found