Thanks Markus, that's clarified it perfectly. Is that documented anywhere?

Also, this seems to be a recent addition - certainly after revision
5380. For earlier versions (and until we upgrade), is a manual flush
like this the best workaround?

            ActiveRecordMediator.GetSessionFactoryHolder().CreateSession(typeof
(Client)).Flush();

I'd just about got examples working myself, but github is having
problems showing new commits so I was holding off sending another mail
to the group until it sorts itself out. Once it does, there will be
full examples at
http://github.com/alexscordellis/nh-ar-oddities/tree/master. If you'd
like, we can perhaps take this code forward as examples /
documentation for the flush semantics?

Alex

2009/6/10 Markus Zywitza <[email protected]>:
> The flushing behaviour without any modifications is:
>
> No Scope: Immediately
> SessionScope: Auto
> TransactionScope: Commit
>
> You should add flush="auto" to your ActiveRecord configuration:
> <activerecord flush="auto">
>  <config>
>   <add key="connection.driver_class"
> value="NHibernate.Driver.SqlClientDriver" />
>   <add key="dialect"
> value="NHibernate.Dialect.MsSql2005Dialect" />
>   <add key='proxyfactory.factory_class'
> value='NHibernate.ByteCode.Castle.ProxyFactoryFactory,
> NHibernate.ByteCode.Castle' />
>   <add key="connection.provider"
> value="NHibernate.Connection.DriverConnectionProvider" />
>   <add key="connection.connection_string" value="Data Source=.;Initial
> Catalog=Test;Integrated Security=SSPI" />
>  </config>
> </activerecord>
>
> This is exactly your required behaviour.
>
> -Markus
>
> 2009/6/10 Alex Scordellis <[email protected]>
>>
>> This seems to be related to the following topics on the dev list, but
>> I can't follow those threads to a complete conclusion that would
>> answer my question
>>
>>
>>  http://groups.google.com/group/castle-project-devel/browse_thread/thread/1707d8cdeecc3869/94a577f3d9eb4114?lnk=gst&q=flush#94a577f3d9eb4114
>>
>>  http://groups.google.com/group/castle-project-devel/browse_thread/thread/ba6c3963f7c4532b/fd3171b7f32d79f9?lnk=gst&q=flush#fd3171b7f32d79f9
>>
>> 2009/6/10 Alex Scordellis <[email protected]>:
>> > I have found that the session is not flushed before I perform a query
>> > using the criteria API, meaning that new objects for which I just
>> > called ActiveRecordMediator.Save are not returned by the query. I
>> > understand why this is (the INSERT is not performed until we flush the
>> > session), but
>> > a) it's surprising for most people. I understood that sessions got
>> > flushed automatically before each query.
>> > b) if I change the primary key of the type to PrimaryKeyType.Identity,
>> > this forces the Save to perform the INSERT to get the DB generated PK
>> > value, so the second query does return the new object
>> >
>> > This was happening when I used a TransactionScope(TransactionMode.New,
>> > IsolationLevel.ReadCommitted, OnDispose.Commit). With the latest trunk
>> > code I can fix it by using a SessionScope(FlushAction.Auto). I tried
>> > various other combinations of transactions and sessions and couldn't
>> > find one where I had a transaction and had an auto flushing session.
>> > What is the right scope construction to give me what I want?
>> >
>> > I'm also worried by point (b), since a change to the code that isn't
>> > visible from the point where I'm making the query is going to affect
>> > the query results. Because the change is not locally visible, it's
>> > going to be pretty tricky to track down bugs caused by this.
>> >
>> > You can see tests that exhibit this behaviour here
>> >
>> > http://github.com/alexscordellis/nh-ar-oddities/blob/bf7d248b08394a1a8e2140c91112239dc5b6f045/NHOddities/FindingRecentlySavedEntitiesWithAQuery.cs
>> > You'll see examples with both types of primary key and with various
>> > types of session scope.
>> >
>> > All this behaviour is against a trunk build of Active.Record. My
>> > current project is using an older build (r5380), which is even worse
>> > as SessionScope(FlushAction.Auto) doesn't fix it. See
>> > wont_find_stuff_just_saved_without_flush_with_flush_mode_auto in
>> >
>> > http://github.com/alexscordellis/nh-ar-oddities/blob/c2ee96d334a89429e41342eec47675d882cf65d2/NHOddities/QueryUsingUnsavedEntity.cs
>> >
>> > Thanks for your help,
>> >
>> > Alex
>> >
>>
>>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to