Session management

Jick,

We have a big problem. It seems like a stale objects. In Hibernate dcumentation I found the following:

In a three tiered architecture, consider using SaveOrUpdate().
When using a distributed architecture, you could pass persistent objects loaded in the middle tier to and from the user interface tier. Use a new session to service each request.

In a two tiered architecture, consider using session disconnection.
Database Transactions have to be as short as possible for best scalability. However, it is often neccessary to implement long running Application Transactions, a single unit-of-work from the point of view of a user. This Application Transaction might span several client requests and response cycles. Either use Detached Objects or, in two tiered architectures, simply disconnect the NHibernate Session from the ADO.NET connection and reconnect it for each subsequent request. Never use a single Session for more than one Application Transaction usecase, otherwise, you will run into stale data

Then they promote the following pattern:
ISession session;
ITransaction tx;

    try
    {
           session = factory.OpenSession();
           tx = session.BeginTransaction();
           // do database work
           tx.Commit();
           session.Close();
    }
    catch (Exception ex)
    {
           tx.Rollback();
           session.Close();
           // further exception handling
    }

We would like to experiment with sessions, but possibilities in the code generated by VP seem very limited. Can you help us with this, please? We are really stuck at this moment.

Cheers,
Tadeusz

Hi Tadeusz,

We believe that USER_DEFINIED session type is what you needed. By applying USER_DEFINED session type, this will create new session on each getSession() call. Operations like save can pass session parameter.

To use USER_DEFINED session type, call this:
PersistentManager.SetSessionType(PersistentManager.SessionType.USER_DEFINED)

Hope this helps.

Best regards,
Jick

Jick,

Thanks! We will try it, but we will have some question concerning this option.

Another question now:

Where can I find explanation of cache option? There are the following possibilities: Disable, Transactional, Read-Write, Non-strict Read-Write, Read-Only. Some of them seem obvious, but we would like to have complete explanation of them, please.

Tnx,
Tadeusz

Hi Tadeusz,

Please read this:
http://www.hibernate.org/hib_docs/reference/en/html/performance.html#performance-cache

Best regards,
Jick

Of course! How did I miss it? Must be stress because of deadlines :wink:

Tadeusz

No problem. Just contact us again if you have any questions.