I am trying to save a complex object which has many referenced elements inside and it works perfectly most of the time.
However in some cases we are getting the below exception,
object references an unsaved transient instance - save the transient instance before flushing or set cascade action for the property to something that would make it autosave. Type: Namespace.Core.Client.ClientDetails, Entity: Namespace.Core.Client.ClientDetails
The problem is, there are around 12 ClientDetails elements inside my complex object which we are trying to save.Is there a way to identify which object instance caused this issue? through NHibernate logging or some other way? My code sample used for save as below,
_repository.Save<SuperParent>(obj);
_repository.Flush();
Please note when i set the Nhibernate show_sql to true i am able to see all the queries properly generated, but when the flush is called, the exception is thrown.
Please help to resolve the issue.
The exception means that there is an unsaved instance of ClientDetails
referenced by this object. You have to either save it manually before saving the parent
session.Save(Parent.SomeDetail);
or set Cascade.SaveOrUpdate
on the reference-mappings in the parent mapping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With