Okay,
So I'm inserting new records, Retreived by ADO and inserting with Nhibernate, cause that's how it done here at JCDC. I'm getting NHibernate.NonUniqueObjectException for no discernible reason.
Well, there is a reason. Nhibernate has lots of weird rules about the map it uses to keep track of changes to the state before .commit is called. When you're updating with objects not retrieved by NHibernate, sometimes it gets squirrely. Wish I had better details but there it is, look at the link above and follow the link there to Aiendes explanation for more details (not better really just more).
But here is how I fixed it, I got ahold of the NH session object and merged the object i'm inserting before I inserted it, and voilia, it stopped throwing an exception.
public void InsertDedHist( DedHistCV userInput )
{
if( IdList.Contains( userInput ) )
{
throw new Exception("BUG FOUND!!!!");
}
else
{
IdList.Add( userInput );
}
try
{
Trace.WriteLine("");
DedHistEO temp = new DedHistEO();
temp.InjectFrom( userInput );
DedHistEO mergedEo = (DedHistEO)JcdcDb.GetSession().Merge( temp );
DedHistEO userInput2 = JcdcDb.Insert<DedHistEO>( mergedEo );
}
catch ( Exception ex )
{
throw;
}
}