friend... when you create a new a instance of something NH don't know that instance and can't persist it by it self...You are associating that instance to the session directly or indirectly trough an instance of a persistent object associated to a session and mapped with a cascade... there is not any kind of magic.
2009/2/10 antoschka <[email protected]> > > No I did not associate the transient objects to a NH session. What > does it make for difference? Why are they persisted? > > On 10 Feb., 18:14, Fabio Maulo <[email protected]> wrote: > > mmmm You are associating that "transient" obj instance to a NH session, > be > > sure of that, in some where. > > > > 2009/2/10 antoschka <[email protected]> > > > > > > > > > > > > > Hi, > > > > > i discovered a strange behavior and would like to know if anybody > > > could explain it to me. > > > > > I create some transient objects (e.g. MyMappedClass myMappedClass = > > > new MyMappedClass ()) which are not yet persistent in the data base. > > > In another part of the program I get some persistent objects using the > > > following code: > > > IList<T> items = null; > > > ISession session = > > > SessionProviderStatic.Instance.GetSession(); // exectueds a > > > sessionFactory.OpenSession() > > > ITransaction trans = null; > > > > > try > > > { > > > > > trans = session.BeginTransaction(); > > > ICriteria query = session.CreateCriteria(typeof(T)); > > > items = query.List<T>(); > > > trans.Commit(); > > > return items; > > > } > > > > > catch (Exception ex) > > > { > > > trans.Rollback(); > > > if (log.IsFatalEnabled) log.Fatal("Error getting > > > items: " + ex.Message, ex); > > > throw; > > > } > > > finally > > > { > > > SessionProviderStatic.Instance.CloseSession(); > > > } > > > > > For some reason the transient objects are now saved after this > > > procedure to the database. I know that a trans.Commit() will cause > > > Flush (using Flushmode AUto or Commit), but this should not cause a > > > saving of transient objects, should it? > > > For this a save/saveOrUpdate/persist should be executed - right. What > > > could be a possible reason for the behavior? > > > > > Thanks antoschka > > > > -- > > Fabio Maulo > > > -- 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 -~----------~----~----~----~------~----~------~--~---
