1
votes

I'm programming a project in which I need Hibernate technology. I got this stack trace and I don't know how to fix it. Any help please ?

Here is my stack trace, I got these two errors :

SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding. SLF4J: Your binding is version 1.5.5 or earlier. SLF4J: Upgrade your binding to version 1.6.x. or 2.0.x

Here is my HibernateUtils.class

package com.forum.utils;

import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtils { private static final SessionFactory sessionFactory;

// Crée une unique instance de la SessionFactory à partir de // hibernate.cfg.xml static { try { sessionFactory = new AnnotationConfiguration().configure() .buildSessionFactory(); } catch (HibernateException ex) { throw new RuntimeException("Problème de configuration : " + ex.getMessage(), ex); } }

// Renvoie une session Hibernate public static Session getSession() throws HibernateException { return sessionFactory.openSession(); } }

This error triggers from this line :

s = HibernateUtils.getSession();

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>

      <property name="connection.driver_class">org.postgresql.Driver</property>
      <property name="connection.url">jdbc:postgresql://localhost:5432/projetForum</property>
      <property name="connection.username">postgres</property>
      <property name="connection.password">esct</property>
      <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

      <!-- Comportement pour la conservation des tables -->
      <property name="hbm2ddl.auto">update</property>

      <!-- Activation : affichage en console, commentées et formatées -->
      <property name="show_sql">true</property>
      <property name="hibernate.format_sql">true</property>
      <property name="use_sql_comments">true</property>

      <!-- Fichiers à mapper -->
      <mapping class="com.forum.beans.Utilisateur" />
      <mapping class="com.forum.beans.Topic" />

  </session-factory>
</hibernate-configuration>

Here is Hibernate3.0 library and my jstl jars :

enter image description here

3

3 Answers

1
votes

According to your library list, your slf4j-api comes from hibernate-distribution, while slf4j-log4j12 comes from hibernate-annotations. Since slf4j reports a version mismatch between the api and the binding (the slf4j-log4j12) I assume you are mixing incompatible hibernate libraries. For hibernate 3, there is a compatibility matrix telling you which versions of the different packages can be used together: https://community.jboss.org/wiki/HibernateCompatibilityMatrix

Alternatively you could overwrite the versions of either the slf4j-api or the slf4j-log4j12 packages in your build-tool (assuming you use one) and make sure they both have the same version. E. g., if you use slf4j-api 1.6.1, you should make sure the slf4j-log4j12 lib is also of version 1.6.1.

0
votes

you need to add the slf4j-to-log4j bridge to your classpath with the same version as your slf4j api (here 1.6.1) --- http://www.slf4j.org/dist/slf4j-1.6.1.zip

If using maven, add this:

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>

in addition to (probably already added...)

         <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
         </dependency>
0
votes

You can download the hibernate final package from hibernate.org Unzip this zip file and import the jar files under directory (hibernate/lib/required) to your eclipse ide. After that you can download the slf4j.zip from slf4j.org unzip and add the jar file wihich is called slf4j-simple-1.7.6.jar