title: Hibernate + Spring: java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
body: <p>I am trying to include <code>Hibernate 5.0.5</code> to my project which uses <code>Spring 4.2.1.RELEASE</code> and <code>Maven</code>. Unfortunately, I get the error about <code>jboss.logging</code> which is used by Hibernate. </p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [META-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)
          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)
          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
          at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
          at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
          at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
          at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:835)
          at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:530)
          at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:808)
          at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:342)
          at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1380)
          at org.eclipse.jetty.maven.plugin.JettyWebAppContext.startWebapp(JettyWebAppContext.java:320)
          at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1342)
          at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:772)
          at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:259)
          at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:518)
          at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:403)
          at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
          at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
          at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
          at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
          at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:161)
          at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
          at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
          at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
          at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
          at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
          at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
          at org.eclipse.jetty.server.Server.start(Server.java:405)
          at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:106)
          at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
          at org.eclipse.jetty.server.Server.doStart(Server.java:372)
          at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
          at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:457)
          at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:328)
          at org.eclipse.jetty.maven.plugin.JettyRunMojo.execute(JettyRunMojo.java:170)
          at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
          at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
          at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
          at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
          at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
          at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
          at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
          at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
          at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:497)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
          at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
          at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
  Caused by: java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
          at org.hibernate.internal.NamedQueryRepository.checkNamedQueries(NamedQueryRepository.java:149)
          at org.hibernate.internal.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:764)
          at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:495)
          at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
          at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372)
          at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454)
          at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
          ... 64 more
  </code></pre>
  
  <p>This is my <code>applicationContext.xml</code> where <code>mySessionFactory</code> bean is defined.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;context:component-scan base-package="com.sap.user.api.generated"/&gt;
  
      &lt;bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
          &lt;property name="driverClassName" value="org.hsqldb.jdbcDriver"/&gt;
          &lt;property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/&gt;
          &lt;property name="username" value="sa"/&gt;
          &lt;property name="password" value=""/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="myDataSource"/&gt;            
          &lt;property name="hibernateProperties"&gt;
              &lt;value&gt;
                  hibernate.dialect=org.hibernate.dialect.HSQLDialect
              &lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>In my <code>pom.xml</code> for Hibernate I include only </p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
      &lt;version&gt;5.0.5.Final&lt;/version&gt;
   &lt;/dependency&gt;
  </code></pre>
  
  <p><em>What I tried to do?</em></p>
  
  <ol>
  <li>First with Hibernate 5.0.5.Final, I got <code>jboss.logging</code> version <code>3.3.0.Final</code>. This failed.</li>
  <li>Based on <a href="https://stackoverflow.com/a/32913401/1783045">this post</a> I decided to exclude <code>jboss.logging</code> from Hibernate => got <code>3.1.3.GA</code> which is used by Spring. This failed as well.</li>
  <li>Based on <a href="https://stackoverflow.com/a/27842103/1783045">another post</a> I decided to include <code>3.2.0.Final</code>. This failed again with the same error.</li>
  <li>I am using the class <code>org.springframework.orm.hibernate4.LocalSessionFactoryBean</code>, I decided to take it from <code>hibernate5</code> package, but this didn't help again, however, it might be not relevant at this point.</li>
  </ol>
  
  <p><strong>EDIT</strong></p>
  
  <p>I managed to debug this and if I try to go to the declaration of the <code>debugf(String, int)</code> method it throws me not to the raw <code>jboss-logging</code>, but to the Logger class which is inside <code>bean-validator-2.4.0-b31</code> under <code>glassfish</code>.</p>
  
  <p><strong><em>Which jboss.logging version I should use? How can I solve this issue?</em></strong></p>