I am writing an application that incorporates NHibernate.
The load times and everything appear to be well within reason from my initial configuration. However, I am trying to perform a stress test for more of a worse case scenario for the application. This stress test has bumped up the number of objects substantially and I am now saving 3 classes: 2400 Intersections, 9600 Zones, and 5000 Vehicles.
My problem I am running across is trying to save the items to the database for the first time. I create all the items and then attempt to save them via:
Code:
using (var tx = session.BeginTransaction())
{
foreach (Vehicle veh in Program.data.Vehicles.list)
{
session.Save(veh);
}
// Commit transactions
tx.Commit();
}
However, I keep running across a:
Quote:
System.StackOverflowException was unhandled Message: An unhandled exception of type 'System.StackOverflowException' occurred in System.Data.dll
I have tried adding a counter to call Flush every 10 iterations through the loop. The problem is that the Vehicle contains a list of Zones and the Zone contains a list of Vehicles. It just so happens that every vehicle has a list of every zone and vice versa. So calling the first session.Save is not only saving the first Vehicle, but queuing up the saving of every Zone, which in turns saves all the Vehicles.
I have the Zone list in the Vehicle set to inverse = false; therefore, it is saving all the Zones that are in the Vehicle list if they don't exist.
Is there any way to tell NHibernate to commit the changes ever so often so I don't hit the StackOverflowException? I tried adding a counter to Flush the session every 10 saves, but I hit the overflow exception before it ever reaches this. When it saves the first Vehicle, it is saving every Zone. Since every zone contains every Vehicle it is saving every vehicle. I never hit the flush before I get the overflow exception.
I'd really like to be able to just call save on the Vehicle and it cascade the save to the Zone. It will save me a lot of time from having to iterate through both the Zone list and then retouching the Zone again when I save the Vehicle.
*EDIT*
If you need to see the mappings to give me better advice let me know and I'll post them.
*EDIT*
It appears to be choking on the tx.Commit(). Any help getting this resolved would be greatly appreciated.