aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate error on tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate error on tomcat" Watch "Hibernate error on tomcat" New topic
Author

Hibernate error on tomcat

Pablo M�ller
Ranch Hand

Joined: Dec 12, 2006
Posts: 63
Hi,
I posted here because the stack trace is about hibernate, but it I'm not sure that this isn't a tomcat thing.
I have a web application that works fine, but sometimes when deployed to tomcat (5.5.16) I get this Hibernate exception. The strange thing is that it doesn't happen every time the application is started, if I redeploy or restart tomcat it might as well work or throw this again.
Here's the stack trace (there are a few phrases in Spanish, but they aren't relevant, they say that an exception has been thrown):



If someone has any idea, it will be welcome.
Thanks.
Pablo


2B || !2B
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Caused by: java.lang.NoClassDefFoundError: omwa/model/order/discount/Discount

Check what you have deployed. omwa.model.order.discount.Discount needs to be in your application's classpath.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Pablo M�ller
Ranch Hand

Joined: Dec 12, 2006
Posts: 63
Thanks for the reply.
That class is in the classpath, it is deployed with the application. And, since the error can be "solved" simply restarting tomcat, I don't think that's the real problem.
Thanks again!!
Pablo M�ller
Ranch Hand

Joined: Dec 12, 2006
Posts: 63
I just found out that if I restart the server and then redeploy it seems to work every time... but I don't know what it means
Thanks
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Ultimately, it means that omwa.model.order.discount.Discount wasn't in the classpath when the SessionFactory was initialized. Why a redeploy of the same application fixes it I can't say.
Pablo M�ller
Ranch Hand

Joined: Dec 12, 2006
Posts: 63
Well, that's what it seems, but I just tried this:



I'm creating a Discount (it's an interface, FixedDiscount is an implementing class) setting its id, and printing it.
I get the "Discount ID: 1" message in the console and, after that, I get the same error... So first it is in the classpath and then it's not.
Stu Thompson
Hooplehead
Ranch Hand

Joined: Jun 14, 2006
Posts: 136
If discount is an interface, and new FixedDiscount() works, then the error message seems to be saying (and I might have this wrong) that your code is trying to instance an interface and not the class itself...hence the java.lang.NoClassDefFoundError: omwa/model/order/discount/Discount

It might help if you post the hibernate mapping file.

Stu


"This is not to say that design is unnecessary. But after a certain point, design is just speculation." --Philip Chu
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Pablo M�ller:
Well, that's what it seems, but I just tried this:



I'm creating a Discount (it's an interface, FixedDiscount is an implementing class) setting its id, and printing it.
I get the "Discount ID: 1" message in the console and, after that, I get the same error... So first it is in the classpath and then it's not.


What does your HibernateDAOInitializer do?
Pablo M�ller
Ranch Hand

Joined: Dec 12, 2006
Posts: 63
Thanks for the reply,
Here's the mapping file for Discount.
The problem arises when hibernate tries to create a session. I don't it is trying to instantiate any object then. And as I could reference a FixedDiscount as a Discount, I asume It is in the classpath at that moment, so I don't know why it can't be found later, if that's what happens.



Pablo M�ller
Ranch Hand

Joined: Dec 12, 2006
Posts: 63
HibernateDAOInitializer should create the DAOs, but when this error arises, it doesn't get to do it. Before creating the DAOs it tries to create the session, so it calls this method I'm posting here, and fails where it says there. Then the exception that is thrown is risen to the code I posted earlier.



Thanks again.
Stu Thompson
Hooplehead
Ranch Hand

Joined: Jun 14, 2006
Posts: 136
Can we see the Discount.java, please?

If Discount really is an interface, then you cannot actually instance it. Yes, you can instance FixedDiscount which implements Discount, but that is different.

I have never used an interface with hibernate and am suspecting that your hibernate mapping does not accurately describe your interface and two implementing classes. Therefore, I think hibernate is trying to instance a Discount class (java.lang.NoClassDefFoundError: omwa/model/order/discount/Discount) but cannot because it is actually an Interface...and then blows up.


If Discount is actually a proper super class of FixedDiscount, then I don't know what to suggest. I have a very similar arrangement...but my mapping is simpler: E.g.: no proxy attribute, abstract atrribute, etc.

Stu
Pablo M�ller
Ranch Hand

Joined: Dec 12, 2006
Posts: 63
In a desperate action, one of those you do when you don't know what else to try, I moved the libraries that were under shared/lib to the war, and it started working... It seems it was a tomcat issue after all, but I don't know.
Thank you all.. I hope it keeps working this way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate error on tomcat