Code:
Session s = factory.getCurrentSession();
This gets you a session or a new session if one is not already open
A session is what manages your jdbc connection and your annotated/mapped pojo's.
You will find that if you load pojo's in one session and try to save them in another you won't be able to.
Also look here for more information on the sessionfactory
http://www.hibernate.org/hib_docs/v3/ap ... ctory.htmland here for the session
http://www.hibernate.org/hib_docs/v3/ap ... ssion.htmlCode:
s.beginTransaction();
This begins a transaction. Transactions are a way of performing a set of tasks as one large job. In the api it describes this method like this.
Quote:
Begin a unit of work and return the associated Transaction object. If a new underlying transaction is required, begin the transaction. Otherwise continue the new work in the context of the existing underlying transaction. The class of the returned Transaction object is determined by the property hibernate.transaction_factory
Code:
s.getTransaction().commit();
This will commit all of the tasks which were done since the time you called s.beginTransaction()
for instance if you had code like this
Code:
s.beginTransaction();
s.update(myObject01);
s.delete(myObject02);
s.save(myObject03);
s.getTransaction().commit();
Then you would have updated, deleted and saved an object all in one transaction.
Code:
factory.close();
from hibernates api docs
Quote:
Destroy this SessionFactory and release all resources (caches, connection pools, etc). It is the responsibility of the application to ensure that there are no open Sessions before calling close().
You may not however want to close the factory and usually we will close the session instead. As opening and closing connection pools could be very expensive if this is done often.