I have a ScheduledThreadPoolExecutor which runs a bunch of classes at fixed interval. In each of these bunch of runnable classes, a series of database operations & transactions is performed using hibernate, and these are handled manually. The problem is that there are many database operations and as a result there are many beginTransaction and commit in the code.
For example: HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction(); ...//find , get, save...operations HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
Is there a way to tie a hibernate session to the runnable class using good design principles?
The concept is to avoid making "..beginTransaction..or commit.." for every database transaction and let the thread pool in ScheduledThreadPoolExecutor handle the transactions at a higher level.
|