java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.ClassLoadingException

StackOverflow https://stackoverflow.com/questions/23493499

Question

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
Était-ce utile?

La solution

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).

Autres conseils

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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top