Introdução ao Hibernate - exceção: java.lang.NoSuchMethodError: org.slf4j.Logger.isTraceEnabled()Z

2 respostas
ivandasilva

Boa Tarde a todos, estou iniciando o meu aprendizado em Hibernate e não estou conseguindo sequer mapear uma classe. :cry:

Quando ele chega na linha

SessionFactory sessionFactory = config.buildSessionFactory(); ele lança a exceção
java.lang.NoSuchMethodError: org.slf4j.Logger.isTraceEnabled()Z

Abaixo segue os 2 xml e o bean que esta sendo usado para persistência
OBS O hibernate.cfg.xml esta na raíz do projeto

package com.oreilly.hh.data;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
 * Create sample data, letting Hibernate persist it for us.
 */
public class CreateTest {

	public static void main(String args[]) throws Exception {
		// Create a configuration based on the XML file we've put
		// in the standard place.
 		Configuration config = new Configuration();
		config.configure();

		// Get the session factory we can use for persistence
		SessionFactory sessionFactory = config.buildSessionFactory();

		// Ask for a session using the JDBC information we've configured
		Session session = sessionFactory.openSession();
		Transaction tx = null;
		try {
			// Create some data and persist it
			tx = session.beginTransaction();

			Usuario user = new Usuario("Denis Rodrigues da Silva", "De",
					"[email removido]", "Denis", "Denis");
			session.save(user);

			user = new Usuario("Sandra Regina da Silva", "Mã",
					"[email removido]","Sandra","Sandra");
			session.save(user);

			// We're done; make our changes permanent
			tx.commit();

		} catch (Exception e) {
			if (tx != null) {
				// Something went wrong; discard all partial changes
				tx.rollback();
			}
			throw new Exception("Transaction failed", e);
		} finally {
			// No matter what, close the session
			session.close();
		}

		// Clean up after ourselves
		sessionFactory.close();
	}
}

Usuario.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.oreilly.hh.data">
  <class name="com.oreilly.hh.data.Usuario">
  <meta attribute="class-description">
  Primeiro exemplo usando o Hibernate
  </meta>
  
  <id name="id" type="int" column="id">
  <generator class="native"></generator>
  </id>
  
  <property name="nome" column="nome" not-null="true" type="String"></property>
  
  <property name="apelido" column="apelido" type="String"></property>
  
  <property name="email" column="email" not-null="true" type="String"></property>
  
  <property name="usuario" column="usuario" not-null="true" type="String"></property>
  
  <property name="senha" column="senha" not-null="true" type="String"></property>
  
  </class>
</hibernate-mapping>

hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
        
<hibernate-configuration>
  <session-factory>
    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
        
    <!-- Database connection settings -->
    <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
    <property name="connection.url">jdbc:hsqldb:file:C:\Users\ivan\work\ACP\DB\usuarios</property>
    <property name="connection.username">sa</property>
    <property name="connection.password"></property>
    <property name="connection.shutdown">true</property>
        
    <!-- JDBC connection pool (use the built-in one) -->
    <property name="connection.pool_size">1</property>
        
    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>
        
    <!-- Disable the second-level cache  -->
    <property
     name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        
    <!-- disable batching so HSQLDB will propagate errors correctly. -->
    <property name="jdbc.batch_size">0</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>
    
    <!-- disable batching so HSQLDB will propagate errors correctly. -->
    <property name="jdbc.batch_size">0</property>
    
    <!-- List all the mapping documents we're using -->
    <mapping resource="com/oreilly/hh/data/Usuario.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

Abaixo estão os jar’s do meu classpath
hibernate3.jar
hibernate-testing.jar
cglib-2.2.lib
antlr-2.7.6.jar
common-collections-3.1.jar
dom4j-1.6.1.jar
javassist-3.9.0.GA.jar
jta-1.1.jar
slf4j-log4j12-1.0.1.jar
slf4j-api-1.5.8.jar
apache-log4j-1.2.15.jar
slf4j-0.9.4-jdk14

Desde já, muito obrigado a todos !

2 Respostas

ivandasilva

Consegui resolver o problema, iniciei um projeto utilizando Hibernate pelo Netbeans 6.5 e peguei todos os jars. e coloquei no meu classpath.

R

Boa tarde Ivan, to com o mesmo problema só que uso o eclipse. Quais jars voce colocou no seu classpath? Obrigado

Criado 19 de agosto de 2009
Ultima resposta 21 de ago. de 2009
Respostas 2
Participantes 2