Hi,
I'm trying to make my services transactional by using AbstractPlatformTransactionManager (with a HibernateTransactionManager instance via IoC). Here is my code:
protected ModelAndView handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object, BindException bindException) throws Exception {
TransactionStatus ts = null;
ArrayList libros = null;
try{
Libro libro = (Libro)object;
ts = getTransactionManager().getTransaction(null);
libros = librosDAO.selectLibroByTematica(Libros.TEMATICA);
libro.setISBN("gonzalo isbn");
librosDAO.updateLibro(libro);
Libro libro2 = new Libro();
libro2.setTematica("2");
libro2.setTitulo("nuevo titulo");
libro2.setPaginas(libro.getPaginas());
librosDAO.insertLibro(libro2);
getTransactionManager().commit(ts);
}catch(DataAccessException e){
getTransactionManager().rollback(ts);
e.printStackTrace();
}
The fact is that I think I don't really understand how spring does really do it to manage hibernate transactions. When does the transaction starts? I haven't such method like "tx.doBeginTransaction()", so, when does it start?
Also, I don't really understand how Spring manages sessions with HibernateDaoSupport and HibernateTemplate. I've been seeing this classes source code, and I don't really catch when sessions are opened and closed, so I know how to use it, but not really know how it works :-/
Thanks for the help.
|