Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Hibernate and Eclipse..

Thread view: 
sickness - 25 Apr 2006 18:35 GMT
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
sickness - 25 Apr 2006 18:59 GMT
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)

--
sickness - 25 Apr 2006 19:30 GMT
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;
    }
   
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.