Hibernate version:2.0
<?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="Order"
table="manylist"
dynamic-update="false"
dynamic-insert="false">
<id
name="id"
column="ID"
type="java.lang.Long"
unsaved-value="null">
<generator class="native">
</generator>
</id>
<property
name="description"
type="java.lang.String"
update="true"
insert="true"
column="description"/>
</class>
</hibernate-mapping>
<?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">
</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">
<keycolumn="customer_id">
</key>
<one-to-many class="Order"/>
</set>
</class>
</hibernate-mapping>
Code:
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{
Configuration cfg = new Configuration()
.addClass(Customer.class)
.addClass(Order.class);
SessionFactory sf = cfg.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:
(cfg.Environment 378 ) Hibernate 2.0 final
(cfg.Environment 407 ) hibernate.properties not found
(cfg.Environment 427 ) using CGLIB reflection optimizer
(cfg.Environment 437 ) JVM proxy support: true
(cfg.Configuration 283 ) Mapping resource: Customer.hbm.xml
(mapping.Collection 174 ) Mapping class: Customer -> customers
(cfg.Configuration 283 ) Mapping resource: Order.hbm.xml
(mapping.Collection 174 ) Mapping class: Order -> manylist
(mapping.Collection 976 ) Mapping collection: Customer.orders -> manylist
java.lang.ExceptionInInitializerError
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:613)
at GetReport.main(GetReport.java:27)
Caused by: java.lang.IllegalStateException: No backend found
at net.sf.cglib.CodeGenerator.<init>(CodeGenerator.java:127)
at net.sf.cglib.KeyFactoryGenerator.<init>(KeyFactoryGenerator.java:93)
at net.sf.cglib.KeyFactory.create(KeyFactory.java:114)
at net.sf.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:318)
... 2 more
Exception in thread "main"
MySql Server 4.1
What seems to be the problem here? Im new to hibernate so this might just be a stupid problem