facebook

hibernate

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #226378 Reply

    peerly
    Member

    Hi there,
    Im working with hibernate and when I try and run the class that does all the magic, I get a nasty exception:

    
    net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found
        at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:694)
        at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:717)
        at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:705)
        at hbn.GetReport.main(GetReport.java:29)
    Exception in thread "main"

    This is impossible because I pasted the hibernate.cfg.xml file in every sub directory I could find. Can anyone help me?

    
    package hbn;
    
    import net.sf.hibernate.HibernateException;
    import net.sf.hibernate.Session;
    import net.sf.hibernate.SessionFactory;
    import net.sf.hibernate.Transaction;
    import net.sf.hibernate.cfg.Configuration;
    import java.util.*;
    
    public class GetReport {
        public GetReport(){
            
        }
        
    public static void main(String[]args) throws Exception{
    
        SessionFactory sf = new Configuration().configure().buildSessionFactory();
        Session sess = sf.openSession();
        Transaction tx = null;
        try {
            tx = sess.beginTransaction();
    
            List ls = sess.find("from Customer");
            for (Iterator it = ls.iterator(); it.hasNext();) {
                Customer cr = (Customer) it.next();
                System.out.println( "Animal '" + cr.getName() +
                "' its class is: " + cr.getClass().getName());
                System.out.print("Makes sound: ");
                
                }
            tx.commit();
        } catch (HibernateException e) {
            if (tx!=null) tx.rollback();
            throw e;
            }
            finally {
            sess.close();
            }
    }
    }
    
    #226392 Reply

    Riyad Kalla
    Member

    This is impossible because I pasted the hibernate.cfg.xml file in every sub directory I could find. Can anyone help me?

    Hah, it just needs to be in the root of your /src directory.

    #226926 Reply

    theaim
    Member

    Hallo,
    ich habe exact das selbe Problem. Ich habe die Config-File im Verzeichniss von wo ich die Application aufrufe, sowie auch dort wo der Source sich befindet. Es hat mit der Konstellation auch schon funktioniert.
    Die Datei ist somit auch im Root vom Project.
    Doch leider kann hibernate die Datei nicht mehr finden. Sogar wenn ich dem Configurator die Datei komplett angebe funktioniert es nicht.
    Es ist wie verhext. Kann mir jemand helfen?
    Thx,
    TheAim

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: hibernate

You must be logged in to post in the forum log in