title: java.lang.NoClassDefFoundError: Could not initialize class com.DatabaseHandler.DBHandler
body: <p>I'm trying to host my first backend server via heroku. I have already hosted a mysql server (also on heroku) that I have been able to connect to from my local using both my java servlet and mysql workbench.</p>
  
  <p>I used heroku's git integration to push my servlet to their servers, and as far as I can tell, my tomcat server IS running. When I try to hit one of my urls I get an error message.</p>
  
  <p>The only one I can see that matters is the last one.</p>
  
  <p>java.lang.NoClassDefFoundError: Could not initialize class com.DatabaseHandler.DBHandler.</p>
  
  <p>From what I can understand, this is being caused because my static initialization for my session handler is failing.</p>
  
  <p>I've double checked all of my connections, made sure my mysql drivers were correct, added the mysql driver to the buildpath just in case heroku can't find it, and a host of other things.</p>
  
  <p>Most of my google searches have come up fruitless with solutions I've already tried, or answers that don't pertain to my problem.</p>
  
  <p>Article Controller</p>
  
  <pre class="lang-java prettyprint-override"><code>public class ArticleService {
      Session session;
  
      public ArticleService() {
          this.session = DBHandler.getSessionFactory().openSession();
      }
  
      public List&lt;Article&gt; getAllArticles() {
          List&lt;Article&gt; list = session.createQuery("from Article").list();
          return list;
      }
  
      public ArticleModelView getArticlePage(int pageNumber, int itemsPerPage) {
          ArticleModelView avm = new ArticleModelView();
  
          Query q = session.createQuery("from Article");
          q = q.setFirstResult(pageNumber*itemsPerPage);
          q = q.setMaxResults(itemsPerPage);
  
          avm.articles = q.list();
          int temp = session.createQuery("from Article").list().size();
          temp = temp % itemsPerPage == 0 ? temp/itemsPerPage - 1: temp/itemsPerPage;
  
  
          avm.maxPageSize = temp;
  
          return avm;
      }
  }
  
  </code></pre>
  
  <p>Database Handler</p>
  
  <pre class="lang-java prettyprint-override"><code>public class DBHandler
  {
      private static final SessionFactory sessionFactory;
  
      static {
          try {
              sessionFactory =  new AnnotationConfiguration().configure().buildSessionFactory();
  
          } catch (Throwable ex) {
              System.err.println("Initial SessionFactory creation failed." + ex);
              throw new ExceptionInInitializerError(ex);
          }
      }
  
      public static SessionFactory getSessionFactory() {
          return sessionFactory;
      }
  
      public static void shutdown() {
          getSessionFactory().close();
      }
  }
  </code></pre>
  
  <p>Hibernate Config</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://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
   &lt;session-factory&gt;
    &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
    &lt;property name="hibernate.connection.url"&gt;*******?reconnect=true&lt;/property&gt;
    &lt;property name="hibernate.connection.password"&gt;******&lt;/property&gt;
    &lt;property name="hibernate.connection.username"&gt;******&lt;/property&gt;
    &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLInnoDBDialect&lt;/property&gt;
    &lt;property name="show_sql"&gt;true&lt;/property&gt;
    &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
    &lt;mapping class="com.dailybagel.user.resources.User"/&gt;
    &lt;mapping class="com.dailybagel.article.resources.Article"/&gt;
   &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>When I visit that url with local host the application correctly pings the hosted mysql server and returns the contents of that table.</p>
  
  <p>The goal is to get the hosted servlet to do that same thing.</p>