-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Java + Hibernate
PostPosted: Mon Apr 18, 2011 7:43 am 
Newbie

Joined: Mon Apr 18, 2011 7:33 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.