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