1.

Explain Session?

Answer»

The session object is used to connect with a database. It is light-weight and is instantiated every time a database connection is required. Sessions are not THREAD SAFE and so should not be kept open for long. These objects should be created as needed and should be destroyed if not in use. Sessions hold a first-level cache of data. The org.hibernate.Session interface provides methods to INSERT, update and delete the object. It ALSO provides factory methods for Transaction, Query and Criteria. 

The main functionality of Session objects is to provide create, read and delete operations to the INSTANCES of the mapped entity classes. The instances may be in one of the following states at any given point. 

  1. Transient: When an instance of a persistent class is not associated with a session, has no database representation and has no identifier value, such an instance is considered to be in the transient state 
  2. Persistent: An instance becomes persistent when it is associated with a session, has database representation and has an identifier value   
  3. Detached: An instance is detached, once the Hibernate session is closed. 

A session instance becomes serializable if its persistent class or classes is/are serialised. If a session throws an error, the transaction has to be rolled back and the session instance has to be deleted. 



Discussion

No Comment Found