Re: Hibernate and Eclipse..
these're my classes
---
public class ToolStudente {
public List listaStudenti () {
Session session =
HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List result = session.createQuery("from Studenti").list();
session.getTransaction().commit();
return result;
}
}
---
public class HibernateServlet extends javax.servlet.http.HttpServlet
implements javax.servlet.Servlet {
public HibernateServlet() {super();}
protected void service(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
ToolStudente ts = new ToolStudente();
List studenti = ts.listaStudenti();
for (int i=0; i < studenti.size(); i++){
Studenti thestudent = (Studenti) studenti.get(i);
System.out.println("Studente: " + thestudent.getCognome() +
thestudent.getNome()
+ " matricola: "+ thestudent.getMatricola());
}
}
---
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new
Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}