NHibernate ManyToMany Relationship Cascading AllDeleteOrphan StackOverflowException

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-06-14T21:05:47Z Indexed on 2010/06/14 21:32 UTC
Read the original article Hit count: 352

I have two objects that have a ManyToMany relationship with one another through a mapping table. Though, when I try to save it, I get a stack overflow exception. The following is the code for the mappings:

//EventMapping.cs
HasManyToMany(x => x.Performers).Table("EventPerformer").Inverse().Cascade.AllDeleteOrphan().LazyLoad().ParentKeyColumn("EventId").ChildKeyColumn("PerformerId");


//PerformerMapping.cs
HasManyToMany<Event>(x => x.Events).Table("EventPerformer").Inverse().Cascade.AllDeleteOrphan().LazyLoad().ParentKeyColumn("PerformerId").ChildKeyColumn("EventId");

When I change the performermapping.cs to Cascade.None() I get rid of the exception but then my Event Object doesn't have the performer I associate with it.

//In a unit test, paraphrased
event.Performers.Add(performer); //Event
eventRepository.Save<Event>(event);
eventResult = eventRepository.GetById<Event>(event.id); //Event
eventResult.Performers[0]; //is null, should have performer in it

How should I be writing this properly? Thanks

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about stackoverflow