• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.ClassNotFoundException: org.hibernate.MappingException

 
Jason Trinity
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to add ehcache to my project. I started with an older version of ehcache but was having problems, so I went with hibernate-ehcache-3.6.10. I have added the following properties to my config:



I added the libraries in Eclipse by righlt-clicking Referenced Libraries -> Build Path -> configure Build Path... -> Add JARs..., and then went to the Order and Export tab and added them as export and put them in order. And I have the following libraries in my classpath:



But when I try to run as an Eclipse Application, I get this exception:

eclipse.buildId=unknown
java.version=1.7.0_80
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments: -product MYPROJECT.product
Command-line arguments: -product MYPROJECT.product -data C:\Users\me\workspace_libs/../runtime-MYPROJECT.product -dev file:C:/Users/me/workspace_libs/.metadata/.plugins/org.eclipse.pde.core/MYPROJECT.product/dev.properties -os win32 -ws win32 -arch x86_64 -consoleLog

!ENTRY org.eclipse.osgi 4 0 2016-02-25 10:01:18.189
!MESSAGE Application error
!STACK 1
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [dataAccess-config.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/MappingException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at com.company.myproject.controllers.ApplicationSettingsController.<init>(ApplicationSettingsController.java:39)
at com.company.myproject.controllers.ApplicationSettingsController.getInstance(ApplicationSettingsController.java:49)
at com.company.myproject.client.application.Application.start(Application.java:26)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/MappingException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2595)
at java.lang.Class.getConstructor0(Class.java:2895)
at java.lang.Class.getDeclaredConstructor(Class.java:2066)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:54)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)
... 29 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.MappingException cannot be found by MYPROJECT_1.0.0
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 35 more


No idea if its a configuration or a dependency error. Any help is appreciated. I have another post with a similar problem, but different library versions, and a different exception. I'll take whatever works.
Thanks.
 
Roel De Nijs
Sheriff
Posts: 10763
148
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems you have posted exactly the same question on SO. Please BeForthrightWhenCrossPostingToOtherSites. Thanks!
 
Roel De Nijs
Sheriff
Posts: 10763
148
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First thing to verify: can you find the org.hibernate.MappingException class in one of your dependencies? If you can, is this jar part of your classpath?
 
Jason Trinity
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:Seems you have posted exactly the same question on SO. Please BeForthrightWhenCrossPostingToOtherSites. Thanks!


Sorry, I just need this answered soon, since I've spent over a week trying to get this working. Would just adding something like (crosspost from Stackoverflow) on the title be enough, or is x-posting forbidden? I'm just trying to reach more people.
 
Jason Trinity
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:First thing to verify: can you find the org.hibernate.MappingException class in one of your dependencies? If you can, is this jar part of your classpath?


hibernate-core-3.6.10.Final.jar has org.hibernate.MappingException.class, and it's in my classpath
 
Roel De Nijs
Sheriff
Posts: 10763
148
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason Trinity wrote:Would just adding something like (crosspost from Stackoverflow) on the title be enough, or is x-posting forbidden? I'm just trying to reach more people.

It's definitely not forbidden on CodeRanch. But be honest about it: e.g. at the bottom of your post, you could easily add something like "I have posted this question also on StackOverflow" together with the link of the question. Otherwise it could be possible that someone spends 2-3 hours of his/her precious free time to answer your question, while you have already got an answer/solution.
 
Roel De Nijs
Sheriff
Posts: 10763
148
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason Trinity wrote:hibernate-core-3.6.10.Final.jar has org.hibernate.MappingException.class, and it's in my classpath

Ok! So the class is definitely on the classpath. Now we have to wonder why it's not found during project startup. It seems you are using an Eclipse project to run your application. Is this intended? If it's not, try to use a simple Java application instead. Here you'll find an example to create the Hibernate Application in Eclipse IDE
 
Jason Trinity
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just started working in this project a few weeks ago and its been running as an Eclipse Application for years. I don't know how much work would be to run it as a Java Application, but I can try.
 
Roel De Nijs
Sheriff
Posts: 10763
148
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason Trinity wrote:I just started working in this project a few weeks ago and its been running as an Eclipse Application for years. I don't know how much work would be to run it as a Java Application, but I can try.

Oh, it's an existing project! Then there's no need to try and run it as a Java application. I thought you were creating a project from scratch and I wanted to eliminate all unnecessary complexities until you had a working application. And then you could add the necessary complexities again one by one. But this doesn't apply in your situation.

And when did this error occurred for the first time? When you added hibernate-ehcache-3.6.10 to the classpath? Or when you added some specific ehcache config to your configuration files?

 
Jason Trinity
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done so much stuff that I can't even reproduce this issue when I checkout the project and try to modify it.

Here is a list of things I've done:

-The project already had hibernate. It had a hibernate3.jar that I figured out was hibernate-3.6.0-CR2. I replaced it with hibernate-core-3.6.10.Final.jar. The code ran fine.
-Added ehcache-core-2.4.3.jar and hibernate-ehcache-3.6.10.Final.jar, and the code worked fine.
-Added the following lines to the project's config file in the <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> bean, under <property name="hibernateProperties">



and I get the error java.lang.ClassNotFoundException: net.sf.ehcache.hibernate.EhCacheRegionFactory cannot be found

I still have a copy of the project with the original exception (java.lang.ClassNotFoundException: org.hibernate.MappingException not found), but I do not know why I cannot reproduce this error when I redo these steps.



Another question I had is which of these should I use?

<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>
or
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
?

If I use the second property, I get the error java.lang.ClassNotFoundException: net.sf.ehcache.CacheException cannot be found


 
Roel De Nijs
Sheriff
Posts: 10763
148
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason Trinity wrote:-The project already had hibernate. It had a hibernate3.jar that I figured out was hibernate-3.6.0-CR2. I replaced it with hibernate-core-3.6.10.Final.jar. The code ran fine.
-Added ehcache-core-2.4.3.jar and hibernate-ehcache-3.6.10.Final.jar, and the code worked fine.
-Added the following lines to the project's config file in the <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> bean, under <property name="hibernateProperties">
...
and I get the error java.lang.ClassNotFoundException: net.sf.ehcache.hibernate.EhCacheRegionFactory cannot be found

Seems you already have made some progress

It seems you are using the appropriate properties and class names in your configuration, so I have no clue what's wrong. The EhCacheRegionFactory class is definitely in the ehcache-core-2.4.3.jar dependency. So I'm a bit wondered why this class can not be found. This tutorial provides an Hibernate EhCache Second Level Caching Example. It uses Hibernate 4, but also mentions the differences with Hibernate 3. So maybe you can go through this tutorial and see if you can spot any differences in your configuration. And this article also nicely explains how to configure Hibernate 4 with EhCache higher than 2.4.3, but also mentions how to configure EhCache for Hibernate 3. And finally on the EhCache website itself, you'll find also documentation how to configure it properly.

I think you don't need the hibernate-ehcache-3.6.10.Final.jar dependency, because it seems the ehcache-core-2.4.3.jar dependency already contains the necessary classes (see the net.sf.ehcache.hibernate package). But removing this dependency will probably not solve your issue.

Hope it helps!
Kind regards,
Roel
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!