Ahh, thank you.....I'll make the change then

On Apr 3, 11:33 am, Will Shaver <[email protected]> wrote:
> I think he means you only need to reset the session, and shouldn't
> need to reset the session factory.
>
> On Fri, Apr 3, 2009 at 11:31 AM, joshlrogers <[email protected]> wrote:
>
> > I don't mean to be dense, but what do you mean?
>
> > On Apr 3, 11:29 am, Fabio Maulo <[email protected]> wrote:
> >> Is enough with session.
>
> >> 2009/4/3 joshlrogers <[email protected]>
>
> >> > Disregard please.  I have resolved this issue.
>
> >> > For others who may run into this there seems to be an issue that when
> >> > an exception occurs in the session you can not continue with that
> >> > session.  I resolved by implementing a reset session method whenever
> >> > an exception is caught.  This reset session method disposes of both
> >> > the session and the factory and reinitializes them.
>
> >> >        private void ResetSession()
> >> >        {
> >> >            session.Dispose();
> >> >            sessionFactory.Dispose();
>
> >> >            sessionFactory = (new Configuration().Configure
> >> > ().BuildSessionFactory());
> >> >            session = sessionFactory.OpenSession();
> >> >        }
>
> >> > This allowed subsequent calls to session to work properly.
>
> >> > Thanks,
> >> > Josh
>
> >> > On Apr 3, 10:28 am, joshlrogers <[email protected]> wrote:
> >> > > I am writing tests for my logic layer and I am running into an issue
> >> > > that I have no idea how to debug and I can't find much guidance on the
> >> > > intertubes.  Here is my output from MbUnit.
>
> >> > > ============
>
> >> > > NHibernate: SELECT cwtratingg0_.Id as Id17_0_, cwtratingg0_.Name as
> >> > > Name17_0_, cwtratingg0_.UserAdded as UserAdded17_0_,
> >> > > cwtratingg0_.DateAdded as DateAdded17_0_, cwtratingg0_.UserEdited as
> >> > > UserEdited17_0_, cwtratingg0_.DateEdited as DateEdited17_0_ FROM
> >> > > dbo.tblCWTRatingGroups cwtratingg0_ WHERE cwtratingg0_....@p0; @p0 =
> >> > > '100'
>
> >> > > NHibernate.AssertionFailure: null id in TEAMS_ORM.CWTRatingGroup entry
> >> > > (don't flush the Session after an exception occurs)
> >> > >    at NHibernate.Event.Default.DefaultFlushEntityEventListener.CheckId
> >> > > (Object obj, IEntityPersister persister, Object id, EntityMode
> >> > > entityMode)
> >> > >    at
> >> > > NHibernate.Event.Default.DefaultFlushEntityEventListener.GetValues
> >> > > (Object entity, EntityEntry entry, EntityMode entityMode, Boolean
> >> > > mightBeDirty, ISessionImplementor session)
> >> > >    at
> >> > > NHibernate.Event.Default.DefaultFlushEntityEventListener.OnFlushEntity
> >> > > (FlushEntityEvent event)
> >> > >    at
> >> > > NHibernate.Event.Default.AbstractFlushingEventListener.FlushEntities
> >> > > (FlushEvent event)
> >> > >    at
>
> >> > NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions
> >> > > (FlushEvent event)
> >> > >    at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush
> >> > > (FlushEvent event)
> >> > >    at NHibernate.Impl.SessionImpl.Flush()
> >> > >    at TEAMSData.DataLayer.NHibernateDataProvider.ModifyCWTRatingGroup
> >> > > (CWTRatingGroup ratingGroup) in C:\Source\TEAMS\TEAMS\TEAMSData
> >> > > \DataLayer\NHibernateDataProvider.cs:line 87
> >> > >    at TEAMSLogic.CWTRatingLogic.ModifyCWTRatingGroup(String name,
> >> > > Int32 ratingGroupId, Int32 userEditedId) in C:\Source\TEAMS\TEAMS
> >> > > \TEAMSLogic\CWTRatingLogic.cs:line 35
> >> > >    at TEAMSDataUnitTests.CWTRatingLogicTests.CanModifyCWTRatingGroup()
> >> > > in C:\Source\TEAMS\TEAMS\TEAMSUnitTests\CWTRatingLogicTests.cs:line 44
>
> >> > > ============
>
> >> > > Here is my unit test:
>
> >> > > ============
>
> >> > >         [Test]
> >> > >         [DependsOn(typeof(CWTRatingGroupTests),
> >> > > "CanGetCWTRatingGroupByName")]
> >> > >         [DependsOn("CanAddCWTRatingGroup")]
> >> > >         public void CanModifyCWTRatingGroup()
> >> > >         {
> >> > >             string newGroupName = "Logic Modified Group";
>
> >> > >             CWTRatingGroup ratingGroup =
> >> > > _Provider.GetCWTRatingGroupById(100);
>
> >> > >             _RatingLogic.ModifyCWTRatingGroup(newGroupName,
> >> > > ratingGroup.Id, 1);
>
> >> > >             ratingGroup = _Provider.GetCWTRatingGroupByName
> >> > > (newGroupName);
>
> >> > >             Assert.IsNotNull(ratingGroup);
> >> > >             Assert.AreEqual(1, ratingGroup.UserEdited.Id);
>
> >> > >         }
>
> >> > > ===========
>
> >> > > Here is my logic code:
>
> >> > > ===========
>
> >> > >         public void ModifyCWTRatingGroup(string name, int
> >> > > ratingGroupId, int userEditedId)
> >> > >         {
> >> > >             CWTRatingGroup ratingGroup = provider.GetCWTRatingGroupById
> >> > > (ratingGroupId);
>
> >> > >             ratingGroup.Name = name;
> >> > >             ratingGroup.UserEdited = provider.GetUserById
> >> > > (userEditedId);
>
> >> > >             provider.ModifyCWTRatingGroup(ratingGroup);
> >> > >         }
>
> >> > > ===========
>
> >> > > Finally my data layer
>
> >> > > ===========
>
> >> > >         public void ModifyCWTRatingGroup(CWTRatingGroup ratingGroup)
> >> > >         {
> >> > >             if (ratingGroup.UserEdited == null)
> >> > >                 throw new ArgumentException("UserEdited may not be
> >> > > null");
>
> >> > >             try
> >> > >             {
> >> > >                 ratingGroup.DateEdited = DateTime.Now;
>
> >> > >                 session.Transaction.Begin();
>
> >> > >                 session.Update(ratingGroup);
> >> > >                 session.Flush();
>
> >> > >                 session.Transaction.Commit();
> >> > >             }
> >> > >             catch (Exception)
> >> > >             {
> >> > >                 session.Transaction.Rollback();
> >> > >                 throw;
> >> > >             }
>
> >> > >         }
>
> >> > > ==========
>
> >> > > I have stepped through this and everything looks kosher.  ratingGroup
> >> > > in the DAL has all the required fields populated with valid values.
> >> > > It's Id is definitely populated and is not null.  The exception is
> >> > > thrown when Flush() is called.
>
> >> > > I hope someone has an idea because this code works in another test it
> >> > > was when I added the logic layer in the middle that this code began to
> >> > > throw an exception.
>
> >> > > Thank you in advance,
> >> > > Josh Rogers
>
> >> --
> >> Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to