title: HHH000342: Could not obtain connection to query metadata : Access denied for user
body: <p>I am working on an application with Spring 4.1.6 and Hibernate 4.3. When deploying my application on the test server (Tomcat7) in Eclipse I get the following error: </p>
  
  <pre><code>015-10-29 18:15:28 WARN  JdbcServicesImpl:204 - HHH000342: Could not obtain connection to query metadata : Access denied for user 'root'@'localhost' (using password: YES)
  </code></pre>
  
  <p>I have tried out the following things :</p>
  
  <ol>
  <li>Checked and rechecked my password. </li>
  <li>Granted full access to <code>root@localhost</code> on the db</li>
  </ol>
  
  <p>Here is the log:</p>
  
  <pre><code>2015-10-29 18:15:22 INFO  XmlWebApplicationContext:510 - Refreshing WebApplicationContext for namespace 'recruitment-mvc-servlet': startup date [Thu Oct 29 18:15:22 IST 2015]; root of context hierarchy
    2015-10-29 18:15:23 INFO  XmlBeanDefinitionReader:317 - Loading XML bean definitions from ServletContext resource [/WEB-INF/recruitmentapp-context-config.xml]
    2015-10-29 18:15:24 INFO  XmlBeanDefinitionReader:317 - Loading XML bean definitions from ServletContext resource [/WEB-INF/recruitmentapp-multitenancy-config.xml]
    2015-10-29 18:15:24 INFO  DefaultListableBeanFactory:822 - Overriding bean definition for bean 'loginController': replacing [Generic bean: class [com.ta.app.recruitment.web.controller.LoginController]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [F:\Work\dev\svn\Recruitment Workspaces\Release_1.1_29_10_2015\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Recruitment\WEB-INF\classes\com\ta\app\recruitment\web\controller\LoginController.class]] with [Generic bean: class [com.ta.app.recruitment.web.controller.LoginController]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/recruitmentapp-context-config.xml]]
    2015-10-29 18:15:24 INFO  DefaultListableBeanFactory:822 - Overriding bean definition for bean 'candidateController': replacing [Generic bean: class [com.ta.app.recruitment.web.controller.CandidateController]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [F:\Work\dev\svn\Recruitment Workspaces\Release_1.1_29_10_2015\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Recruitment\WEB-INF\classes\com\ta\app\recruitment\web\controller\CandidateController.class]] with [Generic bean: class [com.ta.app.recruitment.web.controller.CandidateController]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/recruitmentapp-context-config.xml]]
    2015-10-29 18:15:24 INFO  DefaultListableBeanFactory:822 - Overriding bean definition for bean 'interviewerController': replacing [Generic bean: class [com.ta.app.recruitment.web.controller.InterviewerController]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [F:\Work\dev\svn\Recruitment Workspaces\Release_1.1_29_10_2015\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Recruitment\WEB-INF\classes\com\ta\app\recruitment\web\controller\InterviewerController.class]] with [Generic bean: class [com.ta.app.recruitment.web.controller.InterviewerController]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/recruitmentapp-context-config.xml]]
    2015-10-29 18:15:24 INFO  DefaultListableBeanFactory:822 - Overriding bean definition for bean 'recruiterController': replacing [Generic bean: class [com.ta.app.recruitment.web.controller.RecruiterController]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [F:\Work\dev\svn\Recruitment Workspaces\Release_1.1_29_10_2015\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Recruitment\WEB-INF\classes\com\ta\app\recruitment\web\controller\RecruiterController.class]] with [Generic bean: class [com.ta.app.recruitment.web.controller.RecruiterController]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/recruitmentapp-context-config.xml]]
    2015-10-29 18:15:24 INFO  DefaultListableBeanFactory:822 - Overriding bean definition for bean 'searchController': replacing [Generic bean: class [com.ta.app.recruitment.web.controller.SearchController]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [F:\Work\dev\svn\Recruitment Workspaces\Release_1.1_29_10_2015\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Recruitment\WEB-INF\classes\com\ta\app\recruitment\web\controller\SearchController.class]] with [Generic bean: class [com.ta.app.recruitment.web.controller.SearchController]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/recruitmentapp-context-config.xml]]
    2015-10-29 18:15:24 INFO  DefaultListableBeanFactory:822 - Overriding bean definition for bean 'staticController': replacing [Generic bean: class [com.ta.app.recruitment.web.controller.StaticController]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [F:\Work\dev\svn\Recruitment Workspaces\Release_1.1_29_10_2015\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Recruitment\WEB-INF\classes\com\ta\app\recruitment\web\controller\StaticController.class]] with [Generic bean: class [com.ta.app.recruitment.web.controller.StaticController]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/recruitmentapp-context-config.xml]]
    2015-10-29 18:15:26 INFO  PropertySourcesPlaceholderConfigurer:172 - Loading properties file from class path resource [dbparams.properties]
    2015-10-29 18:15:26 INFO  DriverManagerDataSource:133 - Loaded JDBC driver: com.mysql.jdbc.Driver
    2015-10-29 18:15:27 INFO  Version:66 - HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
    2015-10-29 18:15:27 INFO  Version:54 - HHH000412: Hibernate Core {4.3.2.Final}
    2015-10-29 18:15:27 INFO  Environment:239 - HHH000206: hibernate.properties not found
    2015-10-29 18:15:27 INFO  Environment:346 - HHH000021: Bytecode provider name : javassist
    Datasource : org.springframework.jdbc.datasource.DriverManagerDataSource@18229761
  2015-10-29 18:15:28 WARN  JdbcServicesImpl:204 - HHH000342: Could not obtain connection to query metadata : Access denied for user 'root'@'localhost' (using password: YES)
    2015-10-29 18:15:28 INFO  Dialect:145 - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
    2015-10-29 18:15:28 INFO  LobCreatorBuilder:88 - HHH000422: Disabling contextual LOB creation as connection was null
    2015-10-29 18:15:29 INFO  TransactionFactoryInitiator:62 - HHH000399: Using default transaction strategy (direct JDBC transactions)
    2015-10-29 18:15:29 INFO  ASTQueryTranslatorFactory:47 - HHH000397: Using ASTQueryTranslatorFactory
    2015-10-29 18:15:32 DEBUG MapperFactory:49 - Entering &gt;&gt; getMapperInstance()
    2015-10-29 18:15:32 DEBUG MapperFactory:50 - Parameters : jd.mapper
    2015-10-29 18:15:32 DEBUG EntityDTOMapper:62 - Entering &gt;&gt; constructor addressMapper
    2015-10-29 18:15:32 DEBUG MapperFactory:49 - Entering &gt;&gt; getMapperInstance()
    2015-10-29 18:15:32 DEBUG MapperFactory:50 - Parameters : skill.category.mapper
    2015-10-29 18:15:32 DEBUG MapperFactory:67
  </code></pre>
  
  <p>Here is my spring config file entry for the datasource:</p>
  
  <pre><code>&lt;bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="${database.driver}" /&gt;
          &lt;property name="url" value="${database.url}" /&gt;
          &lt;property name="username" value="${database.user}" /&gt;
          &lt;property name="password" value="${database.password}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver" /&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;map&gt;
                  &lt;entry key="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /&gt;
                  &lt;entry key="hibernate.show_sql" value="${hibernate.show_sql}" /&gt;
                  &lt;entry key="hibernate.connection.CharSet" value="utf8" /&gt;
                  &lt;entry key="hibernate.connection.characterEncoding" value="utf8" /&gt;
                  &lt;entry key="hibernate.multiTenancy" value="SCHEMA" /&gt;
                  &lt;entry key="hibernate.multi_tenant_connection_provider"
                      value-ref="tenantConnectionProvider" /&gt;
                  &lt;entry key="hibernate.tenant_identifier_resolver" value-ref="tenantIdentifierResolver"&gt;&lt;/entry&gt;
              &lt;/map&gt;
          &lt;/property&gt;
  </code></pre>
  
  <p>Here are my project dependencies:</p>
  
  <pre><code>&lt;properties&gt;
          &lt;spring.version&gt;4.1.6.RELEASE&lt;/spring.version&gt;
          &lt;hibernate.version&gt;4.3.2.Final&lt;/hibernate.version&gt;
          &lt;log4j.version&gt;1.2.17&lt;/log4j.version&gt;
          &lt;jdk.version&gt;1.7&lt;/jdk.version&gt;
          &lt;json.version&gt;2.4&lt;/json.version&gt;
          &lt;servlet.version&gt;3.0.1&lt;/servlet.version&gt;
          &lt;jsp.version&gt;2.2.1&lt;/jsp.version&gt;
          &lt;jstl.version&gt;1.2&lt;/jstl.version&gt;
          &lt;shiro.version&gt;1.2.3&lt;/shiro.version&gt;
          &lt;context.path&gt;Recruitment&lt;/context.path&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.shiro&lt;/groupId&gt;
              &lt;artifactId&gt;shiro-web&lt;/artifactId&gt;
              &lt;version&gt;${shiro.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
            &lt;groupId&gt;org.apache.shiro&lt;/groupId&gt;
            &lt;artifactId&gt;shiro-core&lt;/artifactId&gt;
            &lt;version&gt;${shiro.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
            &lt;groupId&gt;org.apache.shiro&lt;/groupId&gt;
            &lt;artifactId&gt;shiro-spring&lt;/artifactId&gt;
            &lt;version&gt;${shiro.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.ta.app.recruitment&lt;/groupId&gt;
              &lt;artifactId&gt;recruitment.core&lt;/artifactId&gt;
              &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.11&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;${hibernate.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;5.1.6&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;net.sf.json-lib&lt;/groupId&gt;
              &lt;artifactId&gt;json-lib&lt;/artifactId&gt;
              &lt;version&gt;${json.version}&lt;/version&gt;
              &lt;classifier&gt;jdk15&lt;/classifier&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;${log4j.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;${servlet.version}&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet.jsp-api&lt;/artifactId&gt;
              &lt;version&gt;${jsp.version}&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;jstl&lt;/artifactId&gt;
              &lt;version&gt;${jstl.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;commons-fileupload&lt;/groupId&gt;
              &lt;artifactId&gt;commons-fileupload&lt;/artifactId&gt;
              &lt;version&gt;1.3.1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;commons-io&lt;/groupId&gt;
              &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
              &lt;version&gt;2.4&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
              &lt;artifactId&gt;poi-scratchpad&lt;/artifactId&gt;
              &lt;version&gt;3.8&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
              &lt;artifactId&gt;poi-ooxml&lt;/artifactId&gt;
              &lt;version&gt;3.9&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.pdfbox&lt;/groupId&gt;
              &lt;artifactId&gt;pdfbox&lt;/artifactId&gt;
              &lt;version&gt;1.8.9&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;net.sf.cssbox&lt;/groupId&gt;
              &lt;artifactId&gt;pdf2dom&lt;/artifactId&gt;
              &lt;version&gt;1.3&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt; 
              &lt;groupId&gt;xml-apis&lt;/groupId&gt;
              &lt;artifactId&gt;xml-apis&lt;/artifactId&gt;
              &lt;version&gt;1.4.01&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  </code></pre>
  
  <p>Another project in the same workspace connecting to the same database works just fine. Its main difference is that it does not have the Apache POI dependencies.</p>
  
  <p>Any help on this would be great.</p>