Hibernate and Eclipse..

S

sickness

Hello
It's my first time with Hibernate. I'm using Eclipse with hibernate
tool and Tomcat 5.5.
When I try to build the session Factory I obtain this error:

Initial SessionFactory creation
failed.org.hibernate.HibernateException: /hibernate.cfg.xml not found

Hibernate Tools works well, all the xml file are right configured.
hibernate can't find the hibernate.cfg.xml.
I've put this under the folder 'hibernate_xml' , .. with the others xml
for mapping.
In the Java Build Path I try to add this folder (it's right?) but I've
not resolved my problem :(

I try to change also the instruction like this
sessionFactory = new
Configuration().configure("hibernate_xml/hibernate.cfg.xml").buildSessionFactory();

so I don't know why my application can't find this xml
(on the Hibernate_test\build\classes there're all the xml!)

here is a screenshot of my webapp
http://i3.tinypic.com/wgzrec.gif

thx for your response
bye
sickness
 
S

sickness

maybe I've resolved!? I've done anything!

now tomcat returns me the error:
--
org.hibernate.HibernateException: No CurrentSessionContext configured!
org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:506)
com.hibernate.servlet.ToolStudente.listaStudenti(ToolStudente.java:25)
com.hibernate.servlet.HibernateServlet.service(HibernateServlet.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

--
 
S

sickness

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;
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,732
Latest member
ArronPalin

Latest Threads

Top