-->
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.  [ 4 posts ] 
Author Message
 Post subject: new Configuration() - ClassNotFoundException
PostPosted: Thu Mar 17, 2011 11:51 am 
Newbie

Joined: Thu Mar 17, 2011 11:09 am
Posts: 8
Hello,

I heard from Hibernate some time ago, but I didn't use it so far. Now I need it for a new project and I have to get used to Hibernate. Unfortunately I stuck already at the beginning of learning Hibernate. Although I linked all required libs (see below) and Eclipse does not show any errors, my programm does not find the Configuration Class (see Example1.java). I used the following tutorial: http://www.roseindia.net/hibernate/firstexample.shtml
Unlike in the tutorial, I use the Hibernate Tools for Eclipse, however the generated XML files are almost identical.

Here is my java and XML code. I hope you can help me out...

Contact.java
Code:
package de.hda.test;

public class Contact {
   private Long    id;
   private String    firstname;
   private String    lastname;
   private String    email;
   public void setId(Long id) {
      this.id = id;
   }
   public Long getId() {
      return id;
   }
   public void setFirstname(String firstname) {
      this.firstname = firstname;
   }
   public String getFirstname() {
      return firstname;
   }
   public void setLastname(String lastname) {
      this.lastname = lastname;
   }
   public String getLastname() {
      return lastname;
   }
   public void setEmail(String email) {
      this.email = email;
   }
   public String getEmail() {
      return email;
   }
}


Example1.java
Code:
package de.hda.test;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class Example1 {

   public static void main(String[] args) {
      Session mySession = null;
      
      try {
         SessionFactory mySessionFactory = new Configuration().configure().buildSessionFactory(); // <-- Error!!! (ClassNotFoundException)
         mySession = mySessionFactory.openSession();
         System.out.println("Insert");
         Contact contact = new Contact();
         contact.setFirstname("Mustermann");
         contact.setLastname("Max");
         contact.setEmail("max@mustermann.de");
         contact.setId(1L);
         mySession.save(contact);
         System.out.println("Done!");   
      }catch (Exception e)
      {
         System.out.println(e.getMessage());
      }finally{
         mySession.flush();
         mySession.close();
      }
   }
}

hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
  <property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
  <property name="hibernate.connection.password">*****</property>
  <property name="hibernate.connection.url">jdbc:db2://localhost:50000/HIBETEST</property>
  <property name="hibernate.connection.username">*****</property>
  <property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
  <!-- Mapping files -->
  <mapping resource="de/hda/test/Contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Contact.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 17.03.2011 15:06:17 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="de.hda.test.Contact" table="CONTACT">
        <id name="id" type="java.lang.Long">
            <column name="ID" />
            <generator class="assigned" />
        </id>
        <property name="firstname" type="java.lang.String">
            <column name="FIRSTNAME" />
        </property>
        <property name="lastname" type="java.lang.String">
            <column name="LASTNAME" />
        </property>
        <property name="email" type="java.lang.String">
            <column name="EMAIL" />
        </property>
    </class>
</hibernate-mapping>


Actually nothing should be wrong in such a minimal sample, right?

I linked the following libs:
Code:
hibernate3.jar (Version 3.6.1)
hibernate-testing.jar
antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
javassist-3.12.0.GA.jar
jta-1.1.jar
slf4j-api-1.6.1.jar
db2jcc4.jar


Anybody an idea?

Thank you!
Stefan

PS: I get the following message:
Code:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

I could get rid of that message by linking the jar file "log4j-over-slf4j-1.6.1.jar" instead of "slf4j-api-1.6.1.jar". I downloaded the file from the project page (http://www.slf4j.org/download.html).


Top
 Profile  
 
 Post subject: Re: new Configuration() - ClassNotFoundException
PostPosted: Fri Mar 18, 2011 7:31 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Please read

http://docs.jboss.org/hibernate/core/3. ... on-logging

The most common approach is to simply include slf4j-log4j12.jar into your classpath,
which means choosing log4j as logging system.

The use of log4j-over-slf4j-1.6.1.jar is rather uncommon.


Top
 Profile  
 
 Post subject: Re: new Configuration() - ClassNotFoundException
PostPosted: Wed Mar 23, 2011 6:42 am 
Newbie

Joined: Thu Mar 17, 2011 11:09 am
Posts: 8
Thanks for your answer. I'll read that!

The main problem seems to be an issue with Eclipse on my computer. I tried the same code with Netbeans and it worked. Now that I have a clue, where I have to search, I hope I can fix it...


Top
 Profile  
 
 Post subject: Re: new Configuration() - ClassNotFoundException
PostPosted: Wed Mar 23, 2011 7:07 am 
Newbie

Joined: Thu Mar 17, 2011 11:09 am
Posts: 8
Thread can be closed. It definitely was an issue of my Eclipse installation. I don't know further details. I completley removed all Java compontents and Eclipse from my system and reinstalled them. Now it works. Same code, same libraries.


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

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.