tags:

views:

64

answers:

2

I know that the session is used for the database in Hibernate, but what is the task of the session in database?

Does anyone know about this?

+1  A: 

The session is server side, if by server side you mean as in the web application or client/server application sense.

It is an implementation of the Unit of Work pattern, and does stuff like keeping track of which entities that have been changed, caching of entities and making sure that a specific entity is represented by only one actual instance in the scope of the session.

The NHibernate docs describe ISession like this:

A single-threaded, short-lived object representing a conversation between the application and the persistent store. Wraps an ADO.NET connection. Factory for ITransaction. Holds a mandatory (first-level) cache of persistent objects, used when navigating the object graph or looking up objects by identifier.

Erik Öjebo
+5  A: 

Update: Apologies, my links are to Java APIs (must have missed the nhibernate tag). Regardless, there will be more than one type of session for .NET also.

There will typically be more than one type of session:

Provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user.

  • The hibernate Session is also a server-side object:

The lifecycle of a Session is bounded by the beginning and end of a logical transaction. (Long transactions might span several database transactions.)

The main function of the Session is to offer create, read and delete operations for instances of mapped entity classes.

toolkit