Hibernate version: 2.0
Hi there,
Im working with hibernate and when I try and run the class that does all the magic, I get a nasty exception:
Code:
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?
Code:
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();
}
}
}
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
<class
name="Customer"
table="customers"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Customer.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
/>
<set
name="orders"
lazy="false"
inverse="false"
cascade="none"
sort="unsorted"
>
<key
column="customer_id"
>
</key>
<one-to-many
class="Order"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Customer.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>