title: Specified JDBC Driver com.ibm.db2.jcc.DB2Driver class not found
body: <p>I have spent considerable time researching and trying to figure out where I have gone wrong with my configuration but am completely stuck. From the posts I have been reading the implication is that my driver is not in the classpath. I added the Class.forName("com.ibm.db2.jcc.DB2Driver") line to ensure that the driver is available and it loads in that line. I would really appreciate any suggestions as to what I may have missed.</p>
  
  <p>my code is:</p>
  
  <pre><code>    public class TestHibernateConfig {
  
      private static SessionFactory sessionFactory;
  
      public static void testConfig() {
          try {
              DB2Driver drvr = (DB2Driver) Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
  
              Configuration cfg = new Configuration();
              cfg.configure("hibernate.cfg.xml");
              sessionFactory = cfg.buildSessionFactory();
              Session sess = sessionFactory.getCurrentSession();
              Transaction tx = sess.beginTransaction();
  
              Criteria crit = sess.createCriteria(ItemData.class);
              List items = crit.list();
  
          } catch (Exception e) {
              Logger logger = Logger.getLogger("");
              logger.error(e.getMessage());
          }
      }
  }
  </code></pre>
  
  <p>I get the class not found error when my code hits:
  sessionFactory = cfg.buildSessionFactory();</p>
  
  <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="speed2db2"&gt;
   &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.DB2Dialect&lt;/property&gt;
    &lt;property name="hibernate.connection.driver_class"&gt;com.ibm.db2.jcc.DB2Driver&lt;/property&gt;
    &lt;property name="hibernate.connection.url"&gt;jdbc:db2://appdb:50000/MYTEST&lt;/property&gt;
    &lt;property name="hibernate.connection.username"&gt;myUser&lt;/property&gt;
    &lt;property name="hibernate.connection.password"&gt;myPass&lt;/property&gt;
   &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>persistence.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
      &lt;persistence-unit name="speedPersistUnit"&gt;
          &lt;class&gt;ItemData&lt;/class&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/&gt;
              &lt;property name="hibernate.connection.url" value="jdbc:db2://appdb:50000/MYTEST"/&gt;
              &lt;property name="hibernate.default_schema" value="MYSCHEMA"/&gt;
              &lt;property name="hibernate.connection.username" value="myUser"/&gt;
              &lt;property name="hibernate.connection.password" value="myPass"/&gt;
              &lt;property name="hibernate.connection.driver_class" value="com.ibm.db2.jcc.DB2Driver"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>From within Eclipse I am able to connect to the database and if I go to the Hibernate perspective, I am able to browse the database schema. I am also able to use the HQL editor to load data in my class.</p>
  
  <p>Edit:</p>
  
  <pre><code>09:35:50,338 INFO  [org.hibernate.cfg.Configuration] (http-xxxxxx-xx.xx.xx.xxxx-15081-1) HHH000043: Configuring from resource: /com/newpig/speed2DB2/hibernate.cfg.xml
  09:35:50,340 INFO  [org.hibernate.cfg.Configuration] (http-xxxxxx-xx.xx.xx.xxxx-15081-1) HHH000040: Configuration resource: /com/newpig/speed2DB2/hibernate.cfg.xml
  09:35:50,369 INFO  [org.hibernate.cfg.Configuration] (http-xxxxxx-xx.xx.xx.xxxx-15081-1) HHH000041: Configured SessionFactory: speed2db2
  09:35:52,059 INFO  [org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-xxxxxx-xx.xx.xx.xxxx-15081-1) HHH000402: Using Hibernate built-in connection pool (not for production use!)
  09:36:16,856 ERROR [] (http-xxxxxx-xx.xx.xx.xxxx-15081-1) Specified JDBC Driver com.ibm.db2.jcc.DB2Driver class not found
  </code></pre>
  
  <p>The error happens on this line.</p>
  
  <pre><code> sessionFactory = cfg.buildSessionFactory();
  </code></pre>
  
  <p>Deployed to my .war file:<br/>
  .War<br/>
  |-WEB-INF<br/>
  ||-lib<br/>
  |||-db2jcc4.jar<br/>
  |||-hibernate-core-4.1.2.Final.jar<br/>
  |||-hibernate-entitymanager-4.1.2.Final.jar<br/>
  |||-hibernate-jpa-2.0-api-1.0.1.Final.jar<br/></p>