Den 20 april 2012 15:21 skrev Ramon Smits <[email protected]>:
>
> 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

A query will use the database to decide _which_ objects to return. For
the objects that are already in the session cache, the column values
(except primary key) will be ignored and the existing object returned.


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


Agreed, this is the way to proceed. The session is not intended as a
long lived object.

There are some other tricks though, such as evicting and reloading
objects. See methods on the session object for this. But really, you
should close and reopen the session instead.

/Oskar

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