Ich wuerde gerne eine Verbindung mit Hibernate zu einer DB2 Datenbank herstellen nur funktioniert das nicht ganz.
Hier mal der Code:
Code:
package com.sample;
import java.util.List;
import java.util.Iterator;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import com.sample.HibernateUtil;
public class Test {
public static void main(String[] args) {
SessionFactory ses = HibernateUtil.getSessionFactory();
//Long kastenId = obj.saveKasten("Staette");
//Long kastenId2 = obj.saveKasten("Tiere");
//obj.listKasten();
}
}
Code:
package com.sample;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static SessionFactory sessionFactory = null;
public static SessionFactory getSessionFactory() {
if (sessionFactory == null) {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
ex.printStackTrace();
}
}
return sessionFactory;
}
}
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory name="java:hibernate/SessionFactory">
<!-- properties -->
<property name="dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
<property name="hibernate.connection.password">****</property>
<property name="hibernate.connection.url">*****</property>
<property name="hibernate.connection.username">****</property>
</session-factory>
</hibernate-configuration>
Jetzt krieg ich jedoch die Fehlermeldung:
Code:
Apr 18, 2011 1:26:50 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.1
java.lang.ExceptionInInitializerError
at org.hibernate.cfg.Configuration.reset(Configuration.java:168)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:187)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:191)
at com.sample.HibernateUtil.getSessionFactory(HibernateUtil.java:13)
at com.sample.Test.main(Test.java:110)
Caused by: java.lang.NullPointerException
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:144)
at org.hibernate.cfg.Environment.<clinit>(Environment.java:515)
... 5 more
Hat vlt wer ne Idee