Thanks! I think I got the idea.
the transient objects do have Id = 0 (unsaved-value-seeting = "0").
the objects are associated to other persistent objects. As soon as I
will load a persistent object by a procedure mentioned above, the
transient objects are persisted based on the cascade settings.

Is that about right?

To avoid that I probably need to redefine the cascading modes, right?

Are there other options?

Thanks for your support.

antoschka

On 10 Feb., 18:33, Fabio Maulo <[email protected]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to