/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package controller; import java.util.Collection; import model.Elenco; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /** * * @author simon */ @Controller public class control_servlet { @Autowired private SessionFactory sessionFactory; @RequestMapping("personList.do") public String personList(ModelMap model) { Session dbSession = null; try { dbSession = sessionFactory.getCurrentSession(); dbSession.beginTransaction(); Collection eList; eList = dbSession.createQuery( "from Elenco as e order by e.idelenco") .list(); Elenco[] elencos; elencos = eList.toArray(new Elenco[0]); dbSession.getTransaction().commit(); System.err.println(elencos.length); model.addAttribute("elencos", elencos); } catch (Throwable t) { System.err.println(t); t.printStackTrace(System.err); dbSession.getTransaction().rollback(); model.addAttribute("unrecoverableError", t); } finally { if (dbSession.isOpen()) { dbSession.close(); } } return "personList"; } }