title: Container exception using Hibernate from an external project (server.ContainerException: ... org.hibernate.internal.CoreMessageLogger
body: <p>I'm deploying my REST project on a Glassfish 4.1.1 bundle Netbeans server. As a maven dependency, I have included an external netbeans project already done and tested, that uses Hibernate to provide functionallity. So I should use this Java library project in my REST web services project.</p>
  
  <p>When I debug my REST project, once deployed and started Glassfish in debug mode, REST services are well called and everything is going nice until a call to any method that uses Hibernate (from the external lib project) is needed. Then crashes as shown below in the attached image.</p>
  
  <p>At the starting of Glassfish sever, I noticed these two warnigs:</p>
  
  <pre><code>Warning:   The web application [unknown] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
  Warning:   The web application [unknown] registered the JDBC driver [com.mysql.fabric.jdbc.FabricMySQLDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
  Information:   HV000001: Hibernate Validator 5.1.2.Final
  </code></pre>
  
  <p>And finally, error shown by browser when any Hibernate involucred sentence is invoked is:</p>
  
  <pre><code>exception
  
  javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V
  root cause
  
  org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V
  root cause
  
  java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V
  </code></pre>
  
  <p>I add screenshot:</p>
  
  <p><a href="https://i.stack.imgur.com/ncYdz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ncYdz.png" alt="Error 500 shown"></a></p>
  
  <p>Thank you,
  J.</p>
  
  <p>----------- EDIT WITH SPECIFIC LINE WHERE CRASHES ------------</p>
  
  <pre><code>  public static void openSession(){
          try{
              if (!init){
                  //First inicialization. Force execute static block.
                  Class.forName(SessionFactory.class.getCanonicalName());
                  init = true;
              }
              currentSession = SessionFactory.sessionFactory.getCurrentSession();
              currentSession.beginTransaction();
  </code></pre>
  
  <p>It crashses at Class.forName(SessionFactory.class.getCanonicalName()). I invoke this method in order to force the class SessionFactory to execute its static block method that configures Hibernate only once.
  With suggested solution to downgrade hibernate librery to 4.x.x, it seems to work, but I'm forced to change some newer methods to adapt my code to this version (native querys are different, class Metadata in configuration is not present...). Further, I have new problems when I need to create new basical Hibernate objets for a consult, as Query:</p>
  
  <pre><code>    public static User getUserById(Long id) {
      try {
          String query = "SELECT u FROM User u WHERE u.id =  " + id;
          Query sentence;
  </code></pre>
  
  <p>Crashes as:</p>
  
  <p><a href="https://i.stack.imgur.com/n1sTI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n1sTI.png" alt="enter image description here"></a></p>
  
  <p>Further, I have the same warning at the start:</p>
  
  <pre><code>Warning:   The web application [unknown] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
  
  Warning:   The web application [unknown] registered the JDBC driver [com.mysql.fabric.jdbc.FabricMySQLDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
  Information:   HV000001: Hibernate Validator 5.1.2.Final
  </code></pre>