title: Why is this Hibernate servlet throwing an IllegalAccessError exception?
body: <p>I tried to create a very small web app in NetBeans using Hibernate. I placed <code>hibernate3.jar</code> , <code>log4J-1.2.14.jar</code>, <code>sl4j.api.jar</code>, <code>sl4j-log4ja2-1.5.6.jar</code>, <code>dom4j-1.6.1.jar</code>, <code>jta.jar</code>, and <code>ehcache.jar</code> under the <code>Libraries</code> folder. I also placed <code>hibernate.cfg.xml</code> under the <code>default</code> package of the <code>source</code> folder and default <code>log4j.properties</code> file and <code>Book.hbm.xml</code> under another package of the <code>Source</code> folder. I don't know whether it is right or wrong. I wrote <code>Hibernate Manager</code> class for <code>sessionfactory</code> and controller servlet as follows. But if I run this servlet I get an exception.</p>
  
  <p>Controller servlet:</p>
  
  <pre><code>import java.io.*;
  import java.net.*;
  import Syron.HibernateManager;
  import Syron.BookInfo;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.util.List;
  
  public class ControllerServlet extends HttpServlet {
  
      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
          HibernateManager manager = new HibernateManager(BookInfo.class);
          List categories = manager.findAll();
          request.setAttribute("categories", categories);
          ServletContext context = getServletContext();
          try
          {
              RequestDispatcher dispatcher = context.getRequestDispatcher("/welcomeJSF.jsp");
              dispatcher.forward(request, response);
          }
          catch(Exception es)  {
  
          }
      } 
  
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
          processRequest(request, response);
      } 
  
      protected void doPost(HttpServletRequest request, HttpServletResponse   response)
      throws ServletException, IOException {
          processRequest(request, response);
      }
  
       public String getServletInfo() {
          return "Short description";
      }
  
  }
  </code></pre>
  
  <p>Manager:</p>
  
  <pre><code>import java.util.*;
  
  import org.hibernate.HibernateException;
  import org.hibernate.Session;
  import org.hibernate.util.*;
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  
  //import org.slf4j.impl.*;
  
  public class HibernateManager {
      private Class _cl;
  
      public  HibernateManager(Class cl)
      {
          _cl = cl;
      }
  
      public List findAll() throws HibernateException
      {
          List rv = new ArrayList();
  
          SessionFactory sessionFactory;
          try
          {
              Configuration config = new Configuration();
              config = config.configure("/hibernate.cfg.xml");
              sessionFactory = config.buildSessionFactory();
          }
          catch (HibernateException ex)
          {
              throw new RuntimeException("Exception building SessionFactory: " +ex.getMessage(), ex);
          }
  
          rv = sessionFactory.getCurrentSession().createCriteria(BookInfo.class).list();
          return rv;
      }
  
      public BookInfo findById(int id) throws HibernateException
      {
          Session session = SessionProvider.currentSession();
          BookInfo rv = (BookInfo) session.get(_cl, new Integer(id));
          return rv;
      }
  }
  </code></pre>
  
  <p>Exception:    </p>
  
  <pre><code>java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory
      org.slf4j.LoggerFactory.&lt;clinit&gt;(LoggerFactory.java:60)
      org.hibernate.cfg.Configuration.&lt;clinit&gt;(Configuration.java:152)
      Syron.HibernateManager.findAll(HibernateManager.java:34)
      ControllerServlet.processRequest(ControllerServlet.java:40)
      ControllerServlet.doGet(ControllerServlet.java:62)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  </code></pre>
  
  <p>I tried various things but couldn't fix this. Where did I go wrong? I also placed the <code>commons-logging.jar</code> file instead of <code>sl4j.jar</code> but then I get <code>No class definition found</code> exceptions for <code>org.sl4j.impl.?</code>. So I searched and replaced <code>sl4j-log4ja2-1.5.6.jar</code> and tried again as above. How can I use Hibernate in NetBeans?</p>