title: Hibernate - ClassNotFoundException: com.mysql.jdbc.Driver
body: <p>I'm trying to retrieve data from a MySQL database through Hibernate, but I'm stuck with this error:</p>
  
  <pre><code>Failed to create sessionFactory object.org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver com.mysql.jdbc.Driver could not be loaded
  
  java.lang.ClassNotFoundException: Could not load requested class : com.mysql.jdbc.Driver
  [...]
  </code></pre>
  
  <p>I use a class called DAOFactory to get the hibernate session:</p>
  
  <pre><code>public class DAOFactory {
  
      private static boolean isInstance = false;  
      private static SessionFactory sessionFactory;
      private static ServiceRegistry serviceRegistry; 
      private static Session session;
  
      private DAOFactory() throws ExceptionInInitializerError{        
          if( !isInstance ) {
              try {               
                  Configuration cfg   = new Configuration().configure();              
                  serviceRegistry     = new ServiceRegistryBuilder().applySettings(cfg.getProperties())
                                                  .buildServiceRegistry();
                  sessionFactory      = cfg.buildSessionFactory(serviceRegistry);
              } catch (Throwable ex) {
                  System.err.println("Failed to create sessionFactory object."+ ex);
                  throw new ExceptionInInitializerError(ex);
              }
              session = sessionFactory.openSession();         
              isInstance = true ;
          }               
      }
  
      public static DAOFactory getInstance() {        
          return new DAOFactory() ;
      }
  
      public Session getSession() {
          return session ;
      }
  }
  </code></pre>
  
  <p>hibernate.cfg.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                           "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory name=""&gt;
          &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/enigma&lt;/property&gt;
          &lt;property name="connection.username"&gt;root&lt;/property&gt;
          &lt;property name="connection.password"&gt;&lt;/property&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
          &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
          &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
          &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>And <code>mysql-connector-java-5.1.26-bin.jar</code> is already in the classpath:</p>
  
  <p><img src="https://i.stack.imgur.com/yx8rP.png" alt="classpath"></p>
  
  <p>Does anyone see what I'm missing ?</p>