2

I use spring junit tests, but I get this error message in all tests, since I updated my Hibernate Search, Hibernate and Springframework. In pom.xml I included common.annotations from Hibernate and i can also find it in my library (maven dependency), which should have been included in the classpath. But it seems like that my tests can still not find the class.

Here is the pom.xml config:

<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.5.Final</version>

    </dependency>
    <dependency>
        <artifactId>hibernate-core</artifactId>
        <groupId>org.hibernate</groupId>
        <version>4.3.5.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-search</artifactId>
        <version>5.0.0.Alpha3</version>
    </dependency>


    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-queryparser</artifactId>
        <version>4.7.2</version>
    </dependency>

Here is the error message:

Caused by: java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/ClassLoadingException
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1402)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
    at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
    ... 40 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.ClassLoadingException
    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)
    ... 51 more
4
  • Clean and refresh your app. if problem still persist opt for correct version of annotations jar. Commented May 6, 2014 at 11:34
  • what is scope of maven dependency Commented May 6, 2014 at 13:35
  • Hello Vinay, i added some lines from my pom.xml just now, which are related to the question. Commented May 6, 2014 at 13:56
  • It is perfectly legal to post the solution you found as an answer, and chose it as the correct one after the "couple of days to wait" restriction. Commented May 6, 2014 at 15:34

2 Answers 2

8

Problem solved!

I just added the following codes to my pom.xml:

<dependency>
        <groupId>org.hibernate.common</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>4.0.4.Final</version>
    </dependency>

And I had to write "exclusion hibernate commons annotations" in hibernate-core and hibernate-entitymanager so that the latest version of common-annotation can be downloaded (otherwise it used the integrated older version 4.0.1 and it may not contain this class).

Sign up to request clarification or add additional context in comments.

Comments

0
Add the hibernate-commons-annotations-4.0.4.Final.jar file to project or add the following dependency to pom file for maven build projects.

<dependency>
  <groupId>org.hibernate.common</groupId>
  <artifactId>hibernate-commons-annotations</artifactId>
  <version>4.0.4.Final</version>
</dependency>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.