-->
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.  [ 8 posts ] 
Author Message
 Post subject: java.lang.NoClassDefFoundError: net/sf/hibernate/HibernateEx
PostPosted: Mon Dec 29, 2003 10:53 am 
Newbie

Joined: Mon Dec 29, 2003 10:45 am
Posts: 12
Hi,
I'm a total newbie on Hibernate and I'm starting to thing that I must also be very stupid:)

How come is it possible that I get this "java.lang.NoClassDefFoundError: net/sf/hibernate/HibernateException" -exception on classes that don't use any Hibernate-related classes? They just call a class that fetches data from Oracle using Hibernate.

Here is the code that uses Hibernate:

Code:
public class MenuItems {
    public Materialclass[] getMaterialclasses() throws Exception {
        try {
            Session session = HibernateUtil.currentSession();
            Materialclass[] classes;
            Transaction tx= session.beginTransaction();

            List list = session.find("from Materialclass matClass order by matClass.definition");
            tx.commit();
            classes = (Materialclass[]) list.toArray();
            return classes;
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
            return null;
        } finally {
            try {
               HibernateUtil.closeSession();
            } catch (HibernateException e) {
                throw new Exception(e);
            }
        }
    }
}

It is called from here:
Code:
public void init() {
      int ii = 1;
      Materialclass[] classes;
      MenuItems items = new MenuItems();
      try {
          classes = items.getMaterialclasses();
          setMatclassValues(0, classes[0].getDefinition());
          setMatclassKeys(0, classes[0].getMaterialclass().toString());
          for(int i = 1; i < classes.length; i++) {
                 if(!classes[i].getDefinition().equals(this.getMatclassValues(i-1))) {
                     System.out.println("class:" + classes[i].getDefinition());
                     setMatclassValues(ii, classes[i].getDefinition());
                     setMatclassKeys(ii, classes[i].getMaterialclass().toString());
                     ii++;
                 }
          }
      } catch (Exception e) {
          ;
      }
  }

The exception is thrown at line "MenuItems items = new MenuItems();". I am using Hibernate 2.1.1 and Tomcat 5.0.16. HibernateUtil.class is just like in http://www.hibernate.org/hib_docs/reference/html/quickstart.html

Any help is very welcome.

thanks,
Jari[url][/url]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 29, 2003 11:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Code:
            try {
               HibernateUtil.closeSession();
            } catch (HibernateException e) {
                throw new Exception(e);
            }

MenuItems does use HibernateException


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 29, 2003 12:53 pm 
Newbie

Joined: Mon Dec 29, 2003 10:45 am
Posts: 12
gloeglm wrote:
Code:
            try {
               HibernateUtil.closeSession();
            } catch (HibernateException e) {
                throw new Exception(e);
            }

MenuItems does use HibernateException


Yes it does, but it catches it and throw a "normal" exception, so the HibernateException doesn't go outside that class.

Jari


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 29, 2003 12:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You still need the HibernateException class in the classpath if you use the MenuItems class anywhere. Thats just Java.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 29, 2003 1:14 pm 
Newbie

Joined: Mon Dec 29, 2003 10:45 am
Posts: 12
gloeglm wrote:
You still need the HibernateException class in the classpath if you use the MenuItems class anywhere. Thats just Java.


It is there. I just thought that could it be that here I give HibernateException as a parameter to the Exception that will be thrown:

Code:
} finally {
            try {
               HibernateUtil.closeSession();
            } catch (HibernateException e) {
                throw new Exception(e);
            }
        }


Can't give it a try right now, but I'll do it first thing tomorrow morning. Seems like I've just been blind.

Jari


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 4:55 am 
Newbie

Joined: Mon Dec 29, 2003 10:45 am
Posts: 12
jjari wrote:
gloeglm wrote:
You still need the HibernateException class in the classpath if you use the MenuItems class anywhere. Thats just Java.


It is there. I just thought that could it be that here I give HibernateException as a parameter to the Exception that will be thrown:
Jari


No it's not that. I have no idea what could be the problem. The exception is thrown when creating an instance of a class that never throws HibernateException, it catches them and throws a normal exception. It has no constructors so it shouldn't throw any exceptions when creating an instance, should it?

Jari


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 7:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If there is HibernateException anywhere in your class, you need it in your classpath. This is not just about method signatures! hibernate2.jar is surely missing in your classpath, please check that.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 7:27 am 
Newbie

Joined: Mon Dec 29, 2003 10:45 am
Posts: 12
gloeglm wrote:
If there is HibernateException anywhere in your class, you need it in your classpath. This is not just about method signatures! hibernate2.jar is surely missing in your classpath, please check that.


I solved this one. I thought it'd be enought to have hibernate2.jar included in the web-app, but it wasn't. Thanks for your help.

Jari


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.