title: Hibernate cannot find suitable driver for Derby in Spring MVC webapp
body: <p>I wonder if anyone can explain to me why a Spring and Hibernate webapp works perfectly well in two environments but fails in another? I'm using <code>NetBeans 8.0.X</code> with <code>Tomcat 8.0.3.0</code> and <code>Apache Derby 10.X</code>.</p>
  
  <p>My application's <code>dispatcherservlet</code> is as follows:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:context="http://www.springframework.org/schema/context"
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xmlns:tx="http://www.springframework.org/schema/tx"       
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
                         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
                         http://www.springframework.org/schema/context 
                         http://www.springframework.org/schema/context/spring-context-4.0.xsd 
                         http://www.springframework.org/schema/mvc                            
                         http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd                           
                         http://www.springframework.org/schema/tx    
                         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"&gt;
  
  &lt;!-- Uses annotations in classes for JavaBeans. XML is an alternative. --&gt;
  &lt;mvc:annotation-driven /&gt;   
  
  &lt;!-- Base package. --&gt;
  &lt;context:component-scan base-package="library" /&gt;    
  
  &lt;!-- Model. --&gt;
  &lt;bean id="person" class="library.model.Person" /&gt;
  &lt;bean id="book" class="library.model.Book" /&gt;        
  
  &lt;!-- Spring Controllers. --&gt;
  &lt;bean id="adminController" class="library.controller.admin.AdminController" /&gt;    
  &lt;bean id="personController" class="library.controller.PersonController" /&gt;      
  &lt;bean id="bookController" class="library.controller.BookController" /&gt; 
  &lt;bean id="exceptionController" class="library.controller.ExceptionController" /&gt;     
  
  &lt;!-- Spring Interceptors. --&gt;
  &lt;mvc:interceptors&gt;
      &lt;bean id="clientInterceptor" class="library.interceptor.ClientInterceptor" /&gt;
  &lt;/mvc:interceptors&gt;
  
  &lt;!-- Spring Services. --&gt;
  &lt;bean id="personServiceImpl" class="library.service.PersonServiceImpl" /&gt;    
  &lt;bean id="bookServiceImpl" class="library.service.BookServiceImpl" /&gt;      
  
  &lt;!-- Spring Repositories. --&gt;
  &lt;bean id="personDAOImpl" class="library.dao.PersonDAOImpl" /&gt;    
  &lt;bean id="bookDAOImpl" class="library.dao.BookDAOImpl" /&gt;       
  
  &lt;!-- Spring Validators. --&gt;
  &lt;bean id="personValidator" class="library.validator.PersonValidator" /&gt;    
  &lt;bean id="bookValidator" class="library.validator.BookValidator" /&gt;     
  
  &lt;!-- Spring ViewResolver. --&gt;               
  &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix"&gt;
           &lt;value&gt;/WEB-INF/jsp/&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="suffix"&gt;
          &lt;value&gt;.jsp&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;   
  
  &lt;!-- Spring MesssageSource. --&gt;         
  &lt;bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
      &lt;property name="basename"&gt; 
          &lt;value&gt;/WEB-INF/classes/messages&lt;/value&gt;    
      &lt;/property&gt;    
  &lt;/bean&gt;
  
  &lt;!-- Spring Properties file for Library. --&gt;      
  &lt;bean id="propertiesFactory" class="org.springframework.beans.factory.config.PropertiesFactoryBean"&gt;
      &lt;property name="location"&gt;  
           &lt;value&gt;classpath:library.properties&lt;/value&gt;             
      &lt;/property&gt;
  &lt;/bean&gt;      
  
  &lt;!-- Hibernate DataSource. --&gt;
  &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;   
      &lt;property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" /&gt;        
      &lt;!--property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" /--&gt;
      &lt;property name="url" value="jdbc:derby://localhost:1527/Library" /&gt;
      &lt;property name="username" value="username" /&gt;
      &lt;property name="password" value="password" /&gt;            
  &lt;/bean&gt;   
  
  &lt;!-- Hibernate Interceptors. --&gt;
  &lt;bean id="serverInterceptor" class="library.interceptor.ServerInterceptor" /&gt;
  
  &lt;!-- Hibernate SessionFactory. --&gt;    
  &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;    
      &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;                  
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;    
             &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.DerbyDialect&lt;/prop&gt;                     
             &lt;!--prop key="hibernate.dialect"&gt;org.hibernate.dialect.DerbyTenSixDialect&lt;/prop--&gt;
             &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt;               
  
             &lt;!-- What to do with the database schema. --&gt;
             &lt;prop key="hbm2ddl.auto"&gt;validate&lt;/prop&gt;    
             &lt;!-- validate:    validate the schema, makes no changes to the database.
                  update:      update the schema.
                  create:      creates the schema, destroying previous data.
                  create-drop: drop the schema at the end of the session. --&gt;                 
          &lt;/props&gt;            
      &lt;/property&gt;                                                                                                                                
      &lt;property name="entityInterceptor"&gt;
          &lt;ref bean="serverInterceptor" /&gt;            
      &lt;/property&gt;                                                                                                                                             
      &lt;property name="packagesToScan"&gt;
          &lt;list&gt;
              &lt;value&gt;library.model&lt;/value&gt;                
          &lt;/list&gt;
      &lt;/property&gt;          
  &lt;/bean&gt;
  
  &lt;!-- Hibernate TransactionManagment. --&gt;
  &lt;tx:annotation-driven /&gt;                
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
     &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;  
  </code></pre>
  
  <p></p>
  
  <p>And the errors given when the application builds and fails in the one environment is:</p>
  
  <pre><code>WARN|01 07 2015|16 26 31|http-nio-8080-exec-73|org.hibernate.engine.jdbc.internal.JdbcServicesImpl| - HHH000342: Could not obtain connection to query metadata : No suitable driver found for jdbc:derby://localhost:1527/Library
  INFO|01 07 2015|16 26 31|http-nio-8080-exec-73|org.hibernate.dialect.Dialect| - HHH000400: Using dialect: org.hibernate.dialect.DerbyTenSixDialect
  INFO|01 07 2015|16 26 34|http-nio-8080-exec-73|org.hibernate.engine.jdbc.internal.LobCreatorBuilder| - HHH000422: Disabling contextual LOB creation as connection was null
  ERROR|01 07 2015|16 26 41|http-nio-8080-exec-73|org.springframework.web.context.ContextLoader| - Context initialization failed
  </code></pre>
  
  <p>Which is then causing the wiring of the dependencies to fail.</p>
  
  <p>What do these messages mean?</p>
  
  <p>The application is using <code>Spring 4.0.2</code> with <code>hibernate-core-4.3.10.jar</code>. All dependencies are identical between the three environments and a listing of them follows:</p>
  
  <pre><code>30 Jun 2015  20 26           445,288 antlr-2.7.7.jar
  30 Jun 2015  20 26             4,467 aopalliance-1.0.jar
  30 Jun 2015  20 26           160,519 commons-dbcp-1.4.jar
  30 Jun 2015  20 26            62,050 commons-logging-1.1.3.jar
  30 Jun 2015  20 26         2,834,700 derby.jar
  30 Jun 2015  20 26           582,639 derbyclient.jar
  30 Jun 2015  20 26           313,898 dom4j-1.6.1.jar
  30 Jun 2015  20 26            75,311 hibernate-commons-annotations-4.0.4.Final.jar
  30 Jun 2015  20 26         5,280,098 hibernate-core-4.3.10.Final.jar
  30 Jun 2015  20 27           113,371 hibernate-jpa-2.1-api-1.0.0.Final.jar
  30 Jun 2015  20 26            38,605 jackson-annotations-2.4.0.jar
  30 Jun 2015  20 26           225,306 jackson-core-2.4.1.jar
  30 Jun 2015  20 27           228,552 jackson-core-asl-1.9.7.jar
  30 Jun 2015  20 26         1,074,275 jackson-databind-2.4.1.jar
  30 Jun 2015  20 26           786,084 jackson-mapper-lgpl-1.9.13.jar
  30 Jun 2015  20 26            76,551 jandex-1.1.0.Final.jar
  30 Jun 2015  20 26           714,194 javassist-3.18.1-GA.jar
  30 Jun 2015  20 26           162,126 javax.persistence-2.1.0.jar
  30 Jun 2015  20 26            57,183 jboss-logging-3.1.3.GA.jar
  30 Jun 2015  20 26            11,558 jboss-logging-annotations-1.2.0.Beta1.jar
  30 Jun 2015  20 27            27,717 jboss-transaction-api_1.2_spec-1.0.0.Final.jar
  30 Jun 2015  20 26            20,682 jstl-1.1.2.jar
  30 Jun 2015  20 26            15,071 jta-1.1.jar
  30 Jun 2015  20 26           367,444 log4j-1.2.14.jar
  30 Jun 2015  20 27            52,150 persistence-api-1.0.jar
  30 Jun 2015  20 27            36,364 spring-annotation-base-1.0.2.jar
  30 Jun 2015  20 26           352,730 spring-aop-4.0.2.RELEASE.jar
  30 Jun 2015  20 26           669,044 spring-beans-4.0.2.RELEASE.jar
  30 Jun 2015  20 26           974,272 spring-context-4.0.2.RELEASE.jar
  30 Jun 2015  20 26           960,994 spring-core-4.0.2.RELEASE.jar
  30 Jun 2015  20 26           204,780 spring-expression-4.0.2.RELEASE.jar
  30 Jun 2015  20 26           419,614 spring-jdbc-4.0.2.RELEASE.jar
  30 Jun 2015  20 26           366,844 spring-orm-4.0.2.RELEASE.jar
  30 Jun 2015  20 26           248,204 spring-tx-4.0.2.RELEASE.jar
  30 Jun 2015  20 26           665,015 spring-web-4.0.2.RELEASE.jar
  30 Jun 2015  20 26           660,329 spring-webmvc-4.0.2.RELEASE.jar
  30 Jun 2015  20 26           393,259 standard-1.1.2.jar
  </code></pre>