You can set it when you have a new fresh session for a particular
use-casesession.FlushMode
= FlushMode.Never


2009/2/10 antoschka <[email protected]>

>
> Thank you so much. Well I read some articles were they warned to use
> flushmode never, but I think this is the solution. I git these modes
> available
> always, auto, commit, never, unspecified.
> what about "unspecified"?
> Is there a way to set the flushmode in tne hibernate.cfg.xml? (I do
> not like to put it in the code since my sessionProvider is used in
> other projects as well and they use auto ...)
>
>
> Thanks for your help antoschka
>
>
>
> On 10 Feb., 21:13, Fabio Maulo <[email protected]> wrote:
> > In lines.....
> >
> > 2009/2/10 antoschka <[email protected]>
> >
> >
> >
> >
> >
> > > Hi,
> >
> > > thanks for your help. Actually the entities mentioned are about five
> > > relation apart from each other, but I could narrow it down to a simple
> > > relation
> > > Class1
> > > {
> > >  int Id;
> > >  Class2 ForeignClass;
> > > }
> > > mapping file
> > >  <class name="Class1" table="Class1" lazy="false">
> > >    <id name="Id" column="Id" type="int">
> > >      <generator class="increment" />
> > >    </id>
> > >    <many-to-one name="Class2" cascade="none" column="Class2" not-
> > > null="true" />
> > >  </class>
> >
> > > Class2
> > > {
> > >  int Id;
> > >  IList<Class1> ForeignClass1Collection;
> > > }
> > > mapping file
> > >  <class name="Class2" table="Class2" lazy="false">
> > >    <id name="Id" column="Id" type="int">
> > >      <generator class="increment" />
> > >    </id>
> > >    <bag name="ForeignClass1Collection" inverse="true" lazy="true"
> > > cascade="all">
> > >      <key column="Class2" />
> > >      <one-to-many class="Class1" />
> > >    </bag>
> > >  </class>
> >
> > > now I create a transient object of class1 and add it to the
> > > ForeignClass1Collection in Class2
> > > Class2 persistentClass2 = session.Get<Class2>(class2Id);
> > > Class1 class1 = new Class1(0, persistentClass2);
> > > persistentClass2.ForeignClass1Collection.Add(class1)
> >
> > here you are associating the class1 to the persistent class2; the class2
> is
> > dirty and so the session is dirty.
> >
> >
> >
> > > thats about the standard way how I work with my entities.
> > > class1 is transient and not yet saved. When I do now the following I
> > > run into trouble (class1 is automatically persisted):
> > > trans = session.BeginTransaction();
> > > ICriteria query = session.CreateCriteria(typeof(Class2));
> >
> > You are working in the same dirty-session and you are using AuoFlush. NH
> > discover that you are doing a query in the same "plan" of a dirty
> > persistent-entity so, to ensure the result of the query, NH run the Flush
> > before continue.
> >
> >
> >
> > > items = query.List<T>();
> > > trans.Commit();
> >
> > > thinking about your comments, fabio, I first thought it would be
> > > enough to set the mapping in Class2 to:
> > > ...
> > > <bag name="ForeignClass1Collection" inverse="true" lazy="true"
> > > cascade="save-update">
> > > ...
> > > but same symptoms
> > > setting it to:
> > > ...
> > > <bag name="ForeignClass1Collection" inverse="true" lazy="true"
> > > cascade="none">
> > > ...
> > > will cause an exception:
> > > NHibernate.PropertyValueException - Message="not-null property
> > > references a null or transient ...
> >
> > > What are the possible options to solve the problem?
> >
> > I would say the use of FlushMode.Commit but you are using a transaction
> to
> > do something else so... FlushMode.Commit can't work.
> > You must work using FlushMode.Never that mean that you must explicit call
> > the flush when you really need it.
> > --
> > 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