stack overflow - NHibernate ManyToMany Relationship Cascading AllDeleteOrphan StackOverflowException -
I have two objects that have a lot of relationship with each other through a mapping table. However, when I try to save it, I get stack overflow exception. The code for the following mapping is: .. EventMapping.cs HasManyToMany (X = & gt; x.Performers) .table ("EventPerformer") Invert () Cascade.AllDeleteOrphan () .LazyLoad () ParentKeyColumn ("eventID" ) ChildKeyColumn ("PerformerId") .. //PerformerMapping.cs HasManyToMany & lt; Event & gt; (X = & gt; x.Events). .table ("EventPerformer") Inverse () Cascade.AllDeleteOrphan () LazyLoad () ParentKeyColumn ("PerformerId") ChildKeyColumn (".... eventID");
When I get rid of exceptions (Cascade.None), but then my event item artist is not affiliated with it, to change performermapping.cs.
// In a unit test, paraphrased incident. Form. Add (artist); // Event Event Resorts. Save & lt; Event & gt; (Event); EventResult = eventRepository.GetById & lt; Event & gt; (Event.id); // Event Event Realtor Presentations [0]; // is zero, should be an artist in it
How should I write this correctly? Thank you
You are declaring the relationship as both sides inverted
, Which means that any one is responsible for saving the relationship, and certainly will not work.
Since you are adding events to artists, remove the inverse call from PerformerMapping.
Also, unless you have a flush
session and then the ejected
event, a call to session.Get
one Using the same session, the same object will return.
Comments
Post a Comment