First of all, why are you re-using sessions for independant tasks?

The 1st level cache contains the state that is read for a record. This
should normally behave as when you perform a database transaction.

My guess is that your problem is that in the same session you read the same
entity and expect updated values at the second attemp. The 1st level cache
is not automatically expired or updated when database changes occur.

You have some options:
1. Don't use Session.Get but use a query so fetch the status. Query results
will not be stored in the 1st level cache AFAIK
2. Use a new session for each attemp when you query for the current status.

But I advise to not re-use sessions at all.
--
Ramon

On Fri, Apr 20, 2012 at 2:45 PM, Prakash <[email protected]> wrote:

>
>
> All,
>
>
>
> We are having issues with NHibernate L1 Caching. We have an app which
> updates a record in the database through UI. There is a background job
> which picks up the record and processes it. The issue here is, in the UI we
> change the record status from “Pending Approved” and then to “Release”
> status. When the background picks up the information it is showing the
> status as only “Pending Approved” where as in the database the record is
> updated as Release. We see the problem with GetCurrentSession method and
> the background job uses same thread context for each request and hence new
> session is not created. Find below the GetCurrentSession code. Any ideas of
> how to resolve this issue.
>
>
>
>      public static ISession GetCurrentSession()
>
>         {
>
>             ISession currentSession = null;
>
>             HttpContext context = null;
>
>
>
>             if (IsInWebContext())
>
>             {
>
>                 context = HttpContext.Current;
>
>                 currentSession = context.Items[CurrentSessionKey] as
> ISession;
>
>                 if (currentSession == null || !currentSession.IsOpen)
>
>                 {
>
>                     currentSession = sessionFactory.OpenSession();
>
>                     context.Items[CurrentSessionKey] = currentSession;
>
>                 }
>
>             }
>
>             else
>
>             {
>
>                 currentSession = (ISession)CallContext
> .GetData(CurrentSessionKey);
>
>                 if (currentSession == null || !currentSession.IsOpen)
>
>                 {
>
>                     currentSession = sessionFactory.OpenSession();
>
>                     CallContext.SetData(CurrentSessionKey,
> currentSession);
>
>                 }
>
>             }
>
>             return currentSession;
>
>         }
>
>
>
>         private static bool IsInWebContext()
>
>         {
>
>             return HttpContext.Current != null;
>
>         }
>
> --
> 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.
>



-- 
Ramon

-- 
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