Solucionado (ver solução)
Solucionado
(ver solução)
9
respostas

java.lang.NoClassDefFoundError: org/hibernate/HibernateException

Pessoal, quando rodo o servidor me deparo com esse erro, logo após a aula de configuração do hibernate / JPA e entity Manager:

SEVERE: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class helloworld.app.config.JPAConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean helloworld.app.config.JPAConfiguration.entityManagerFactory()] threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/HibernateException

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean helloworld.app.config.JPAConfiguration.entityManagerFactory()] threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/HibernateException at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590)

9 respostas

SEVERE: Resource read error: Could not load org/hibernate/cache/RegionFactory.class. java.util.zip.ZipException: invalid LOC header (bad signature)

SEVERE: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class helloworld.app.config.JPAConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean helloworld.app.config.JPAConfiguration.entityManagerFactory()] threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/HibernateException

Deu problema em algum jar que foi baixado para o seu projeto, provavelmente o do hibernate mesmo :). Se tiver usando o maven, apague a pasta .m2 da sua home e faça tudo de novo.

como pode ter dado um problema desses se meu pom.xml está exatamente igual ao do vídeo?, tentei apagar a pasta, tentei apagar todo o pom.xml e copiar denovo

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.helloworld</groupId>
  <artifactId>helloworld</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <finalName>helloworld</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
     </plugins>
  </build>
  <properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>

     <!-- Dependências / Base para um projeto Spring MVC com Tomcat 7 -->

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-servlet-api</artifactId>
        <version>7.0.30</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp.jstl</groupId>
        <artifactId>jstl-api</artifactId>
        <version>1.2</version>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jstl-impl</artifactId>
        <version>1.2</version>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- Dependências para logs -->

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.24</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.7.24</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.24</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
        <scope>runtime</scope>
    </dependency>

    <!-- Dependências do JPA e do Hibernate -->

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.15</version>
    </dependency>

</dependencies>

</project>

continua com o mesmo erro... :( O pior é que nem procurando no google acho..

solução!

Tente retirar as dependências do hibernate do seu pom e executar no projeto o comando:

mvn eclipse:clean eclipse:eclipse

E depois:

 mvn clean install -U

Depois insira novamente as dependências e rode novamente o comando:

 mvn clean install -U

Talvez isso funcione. Pode ser problema com o build Path tb, tente verificar a ordem.

Executei os comandos e ainda nada..

A dúvida está como solucionada, deu certo ? O que você fez para ajustar ?

Na verdade não sei porque ficou como solucionada, ainda não consegui resolver o problema.. :(