Hibernate version:
3.0
Name and version of the database you are using:
Microsoft SQL Server 2005
My software has a Flex front ended and a Java back end which uses Hibernate 3 to manipulate my Microsoft SQL Server 2005 database. Everything is deployed within the Tomcat 6.0 server. The software has extremely poor use of sessions/transactions and I'd like to know the best implementation.
Currently I am thinking of binding sessions to the thread using:
Code:
<property name="hibernate.current_session_context_class">thread</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
Then each DAO method would have the following format:
Code:
Session session = HibernateUtil.getCurrentSession();
session.getTransaction().beginTransaction();
//DO SOME DATABASE WORK
session.getTransaction().commit();
Is this implementation good? Is this approach thread safe? Can it be made more efficient? I'm avoiding using the openSession call because I figure getCurrentSession is more efficient?