• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Hibernate 4 & Spring 4 - ReflectionManager Class Not Found

 
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have an Eclipse Maven Project where I'm trying to integrate the latest version of Spring (4.3.0) with Hibernate.  When I attempt to run the application I get the following error

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernate4SessionFactory' defined in class path resource
[Spring-Module.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError:
org/hibernate/annotations/common/reflection/ReflectionManager

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:756)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)

.....

Caused by: java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/ReflectionManager
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:343)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 13 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.ReflectionManager
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 16 more


From what I've researched online it seems that ReflectionManager is part of the Hibernate Annotations jar.  I've added this as a dependency in Maven but it has no effect.  This is my POM




And this is my Spring configuration file



Can anyone see what I'm doing incorrectly here?  Any help is appreciated.

Thanks
 
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Simon Ritchie wrote:Can anyone see what I'm doing incorrectly here?  Any help is appreciated.


It is probably related to a dependency issue. And that could be caused by different reasons. I list a few of them:
1/ If I look at your pom.xml I notice all the org.springframework dependencies have the same version. But you have three org.hibernate dependencies and each dependency has another version. I would try to synchronize these versions as well. I would even verify if you need those three differences, because the Hibernate tutorial only uses one.
2/ Related to (1): one of your other org.hibernate dependencies could include the hibernate-commons-annotations dependency. If that's the case and you especially need the 4.0.4.Final you need to exclude this artifact from the other dependency
3/ There is an issue with your Spring configuration. Although it seems very similar to the configuration used in the Spring ORM tutorial.

This tutorial shows how to integrate Spring with Hibernate using annotation based configuration.

Not related to the issue you are facing, but a useful and valuable tip: you can define a property in pom.xml to set the version for the org.springframework dependenciesAnd then in your dependency you can writeIf you later decide to upgrade the version, you only have to update the property and you are done

And another important note from the Spring ORM tutorial

Object Relational Mapping (ORM) Data Access - Hibernate wrote:As of Spring 4.0, Spring requires Hibernate 3.6 or later. Note that the Hibernate team stopped supporting Hibernate 3 years ago and even phased out support for Hibernate 4.x in late 2015. We therefore recommend Hibernate 5.1 and higher from a 2016+ perspective.



Hope it helps!
Kind regards,
Roel
 
Simon Ritchie
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Roel - I'll give those suggestions a try.
 
Simon Ritchie
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I've made some extensive amendments to my POM.  I'm now using Spring 4.3.0 and Hibernate 4.3.6.  I had initially tried to use Hibernate 5.2.1 but when I ran my main class I got an "Unsuppoerted Major/Minor Version 52" error.  Some Googling suggested that this was probably the result of my Spring being a version out of sync with my Hibernate so I've decided to keep both Spring and Hibernate at 4.X for the time being.

I'm now getting this error

Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '<the name of my Bean>':
Unsatisfied dependency expressed through field 'sessionFactory':
Error creating bean with name 'sessionFactory' defined in class path resource
[<my package>/HibernateConfiguration.class]:
Invocation of init method failed; nested exception is java.lang.NoSuchMethodError:
javax.persistence.Table.indexes()[Ljavax/persistence/Index;; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in class path resource
[<my package>/HibernateConfiguration.class]:
Invocation of init method failed; nested exception is java.lang.NoSuchMethodError:
javax.persistence.Table.indexes()[Ljavax/persistence/Index;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:350)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource
[<my package>/HibernateConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError:
javax.persistence.Table.indexes()[Ljavax/persistence/Index;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:187)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1048)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1018)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:570)
... 15 more
Caused by: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:936)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3788)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3742)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 26 more


From what I've read online this appears to be a problem with the Hibernate JPA dependency.  But I've updated this dependency in my POM to the latest available version and the problem persists.  This is my current POM

 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Simon Ritchie wrote:I had initially tried to use Hibernate 5.2.1 but when I ran my main class I got an "Unsuppoerted Major/Minor Version 52" error.  Some Googling suggested that this was probably the result of my Spring being a version out of sync with my Hibernate so I've decided to keep both Spring and Hibernate at 4.X for the time being.


That's related to the JDK version used to compile the (I assume) Hibernate dependencies and the Java version you use to run your program. Here you'll find an overview of the different major/minor versions. I guess one of the dependencies is compiled with JDK8 and requires (at least) JDK8 to be executed, but you are using an older JDK version.

Simon Ritchie wrote:From what I've read online this appears to be a problem with the Hibernate JPA dependency.  But I've updated this dependency in my POM to the latest available version and the problem persists.


You still are using different versions among your Hibernate dependencies. Why have hibernate-core and hibernate-entitymanager a different version? In fact, you are using a bunch of Hibernate dependencies which I never have added to the pom.xml when creating a Maven project with JPA and Hibernate as persistence provider.

It seems the indexes() method was added to the @Table annotation in JPA 2.1. Although you have a dependency to get the JPA 2.1 annotations, there is probably another dependency which depends on an older version of the JPA annotations. So you ended up having both jars in the classpath as transitive dependencies.

Hope it helps!
Kind regards,
Roel
 
Simon Ritchie
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:

Simon Ritchie wrote:I had initially tried to use Hibernate 5.2.1 but when I ran my main class I got an "Unsuppoerted Major/Minor Version 52" error.  Some Googling suggested that this was probably the result of my Spring being a version out of sync with my Hibernate so I've decided to keep both Spring and Hibernate at 4.X for the time being.


That's related to the JDK version used to compile the (I assume) Hibernate dependencies and the Java version you use to run your program. Here you'll find an overview of the different major/minor versions. I guess one of the dependencies is compiled with JDK8 and requires (at least) JDK8 to be executed, but you are using an older JDK version.

Simon Ritchie wrote:From what I've read online this appears to be a problem with the Hibernate JPA dependency.  But I've updated this dependency in my POM to the latest available version and the problem persists.


You still are using different versions among your Hibernate dependencies. Why have hibernate-core and hibernate-entitymanager a different version? In fact, you are using a bunch of Hibernate dependencies which I never have added to the pom.xml when creating a Maven project with JPA and Hibernate as persistence provider.

It seems the indexes() method was added to the @Table annotation in JPA 2.1. Although you have a dependency to get the JPA 2.1 annotations, there is probably another dependency which depends on an older version of the JPA annotations. So you ended up having both jars in the classpath as transitive dependencies.

Hope it helps!
Kind regards,
Roel



You were right on all counts Roel!  I changed my JDK version from 1.7 to 1.8 and it resolved the Major/Minor version error.

As for my current project, I've switched my Spring version to 4.0.3.RELEASE and my Hibernate version to 3.6.9.Final.  I can now query my database successfully.  Thanks for your help!
 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why drop back all the way to a Hibernate 3 version?
I know it currently works for you, but as Roel posted earlier it has been unsupported for quite a long time now.
 
Simon Ritchie
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Why drop back all the way to a Hibernate 3 version?
I know it currently works for you, but as Roel posted earlier it has been unsupported for quite a long time now.



For reasons of practicality, really.  I'm in a company that has a restrictive policy towards downloading source files of the kind that are needed for Spring and Hibernate.  For most developers it seems that if they want to use the latest versions of either of those technologies they just need to add the dependencies for Spring 4.3.X and Hibernate 5.X to their POM.  My company's web policy doesn't allow that which means I have to download the JARs manually and add them to my local repository in Eclipse using the mvn-install command.  The earlier version of Hibernate was already on our systems so I just used that.

I've just updated my POM to use Spring 4.3.0.RELEASE and Hibernate 5.2.1.Final.  

EDIT: And I just realised I hadn't updated my Spring-Module.xml file

Thanks Dave
 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Simon Ritchie wrote:I've just updated my POM to use Spring 4.3.0.RELEASE and Hibernate 5.2.1.Final.


Awesome! Can you share the final pom.xml? Might be helpful for other ranchers who are struggling to integrate Spring with Hibernate.
 
Simon Ritchie
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Happily!  Here's my final POM.  Also, for the benefit of anyone reading who has a similar issue, I changed the JRE System Library from JDK 1.7.X to JDK 1.8.X

 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Simon Ritchie wrote:Happily!  Here's my final POM.


Thanks! Might be helpful for other ranchers. Have a cow!
 
reply
    Bookmark Topic Watch Topic
  • New Topic