That's pretty much the same code that I wrote. The only difference is that I
added a transaction to the IDbCommand.
using (ITransaction tx = s.Connection.BeginTransaction())
using (IDbCommand command = s.Connection.CreateCommand())
{
command.CommandText = "DELETE FROM Foos";
command.Transaction = tx;
command.ExecuteNonQuery();
tx.Commit();
}
As I recall, NH2 turns off autocommit on the connection, though I'm not sure
why that would make a difference for the 2nd Criteria query.
James
--
James Kovacs, B.Sc., M.Sc., MCSD, MCT
Microsoft MVP - C# Architecture
http://www.jameskovacs.com
[EMAIL PROTECTED]
403-397-3177 (mobile)
On Sun, Sep 7, 2008 at 6:37 PM, Craig Neuwirt <[EMAIL PROTECTED]> wrote:
> I tried this
>
> using (ISession s = OpenSession())
> using (ITransaction tx = s.BeginTransaction())
> {
> Foo result = (Foo)s.CreateCriteria(typeof(Foo))
> .Add(Property.ForName("Name").Eq("Craig"))
> .SetCacheable(true)
> .UniqueResult();
>
> tx.Commit();
>
> Assert.IsNotNull(result);
> }
>
> using (ISession s = OpenSession())
> {
> using (IDbCommand command = s.Connection.CreateCommand())
> {
> command.CommandText = "DELETE FROM Foos";
> command.ExecuteNonQuery();
> }
> }
>
> using (ISession s = OpenSession())
> using (ITransaction tx = s.BeginTransaction())
> {
> Foo result = (Foo)s.CreateCriteria(typeof(Foo))
> .Add(Property.ForName("Name").Eq("Craig"))
> .SetCacheable(true)
> .UniqueResult();
>
> tx.Commit();
>
> Assert.IsNotNull(result);
> }
>
> but it didn't work either. I am doing some silly? What is the correct
> syntax for getting queries into the cache?
>
> thanks,
> craig
>
>
> On Sun, Sep 7, 2008 at 7:02 PM, Ayende Rahien <[EMAIL PROTECTED]> wrote:
>
>> You have to commit the transaction.
>> NH requires transactions for reads as well.
>>
>>
>> On Mon, Sep 8, 2008 at 2:53 AM, Craig Neuwirt <[EMAIL PROTECTED]> wrote:
>>
>>> Hey James,
>>>
>>> You are absolutely correct. Once I added the transaction, my unit test
>>> passed. However, the actual scenario I am trying to get working is assuming
>>> data is in the db already and I perform an initial query. I want that
>>> result to go into the second level cache so it is retrieved from the cache
>>> when the same query is executed. How do I make that happen? I tried
>>> putting transaction around the query, but that didn't work and I don't think
>>> that should be necessary for reads.
>>>
>>> thanks,
>>> craig
>>>
>>>
>>> On Sun, Sep 7, 2008 at 5:14 PM, James Kovacs <[EMAIL PROTECTED]>wrote:
>>>
>>>> I am looking at it right now. Initial investigations... The problem
>>>> seems to stem from lack of transaction handling in the test case. If rather
>>>> than flushing the session, you commit a transaction, the SysCache returns
>>>> data appropriately. I'll post more as I find out more. (Just posting to
>>>> save
>>>> Ayende some time.)
>>>>
>>>> James
>>>> --
>>>> James Kovacs, B.Sc., M.Sc., MCSD, MCT
>>>> Microsoft MVP - C# Architecture
>>>> http://www.jameskovacs.com
>>>> [EMAIL PROTECTED]
>>>> 403-397-3177 (mobile)
>>>>
>>>>
>>>>
>>>> On Sun, Sep 7, 2008 at 4:07 PM, Ayende Rahien <[EMAIL PROTECTED]>wrote:
>>>>
>>>>> Guys,
>>>>> I am going to look at the issue now, will post my results soon
>>>>>
>>>>>
>>>>> On Sun, Sep 7, 2008 at 10:44 PM, Gildas <[EMAIL PROTECTED]>wrote:
>>>>>
>>>>>>
>>>>>> Fabio, I know that I'm still noob in NHibernate and that I may ask
>>>>>> stupid questions. I'm sorry if you are bored with this, but well,
>>>>>> please understand that I'm just trying to resolve a problem I did not
>>>>>> have before upgrading to last NHibernate trunk.
>>>>>>
>>>>>> Going through Rhino code, I can see that my session is created at each
>>>>>> request, so that's not the problem.
>>>>>> Anyway, I still don't have any second level cache. Items are updated
>>>>>> but never retrieved from it.
>>>>>>
>>>>>> Can someone check the test case from craig, which is failing and don't
>>>>>> use any fancy session management ?
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>> On Sep 7, 8:35 pm, "Fabio Maulo" <[EMAIL PROTECTED]> wrote:
>>>>>> > 2008/9/7 Gildas <[EMAIL PROTECTED]>
>>>>>> >
>>>>>> >
>>>>>> >
>>>>>> > > So I'm going to ask if this is the right way to handle sessions ?
>>>>>> From
>>>>>> > > what I remember of NHibernate, NH Sessions must not be stored in
>>>>>> > > HttpContext.Session. I may not understand the reasons why this
>>>>>> done
>>>>>> > > like this in UnitOfWorkApplication, maybe for long transactions
>>>>>> > > management ?
>>>>>> >
>>>>>> > Rhino UoW use httpSession only for long conversation...
>>>>>> > The NhSession CAN be stored in the httpSession simply because is the
>>>>>> "most
>>>>>> > simple" way to manage long-conversations.
>>>>>> > --
>>>>>> > 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
-~----------~----~----~----~------~----~------~--~---