mercredi 1 juillet 2015

Hibernate cannot find suitable driver for Derby in Spring MVC webapp

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 NetBeans 8.0.X with Tomcat 8.0.3.0 and Apache Derby 10.X.

My application's dispatcherservlet is as follows:

<beans xmlns="http://ift.tt/GArMu6"
   xmlns:context="http://ift.tt/GArMu7"
   xmlns:mvc="http://ift.tt/1bHqwjR" 
   xmlns:tx="http://ift.tt/OGfeU2"       
   xmlns:xsi="http://ift.tt/ra1lAU"  
   xsi:schemaLocation="http://ift.tt/GArMu6 
                       http://ift.tt/1cnl1uo 
                       http://ift.tt/GArMu7 
                       http://ift.tt/1ldEMZY 
                       http://ift.tt/1bHqwjR                            
                       http://ift.tt/1kF4x7W                           
                       http://ift.tt/OGfeU2    
                       http://ift.tt/KC395X">

<!-- Uses annotations in classes for JavaBeans. XML is an alternative. -->
<mvc:annotation-driven />   

<!-- Base package. -->
<context:component-scan base-package="library" />    

<!-- Model. -->
<bean id="person" class="library.model.Person" />
<bean id="book" class="library.model.Book" />        

<!-- Spring Controllers. -->
<bean id="adminController" class="library.controller.admin.AdminController" />    
<bean id="personController" class="library.controller.PersonController" />      
<bean id="bookController" class="library.controller.BookController" /> 
<bean id="exceptionController" class="library.controller.ExceptionController" />     

<!-- Spring Interceptors. -->
<mvc:interceptors>
    <bean id="clientInterceptor" class="library.interceptor.ClientInterceptor" />
</mvc:interceptors>

<!-- Spring Services. -->
<bean id="personServiceImpl" class="library.service.PersonServiceImpl" />    
<bean id="bookServiceImpl" class="library.service.BookServiceImpl" />      

<!-- Spring Repositories. -->
<bean id="personDAOImpl" class="library.dao.PersonDAOImpl" />    
<bean id="bookDAOImpl" class="library.dao.BookDAOImpl" />       

<!-- Spring Validators. -->
<bean id="personValidator" class="library.validator.PersonValidator" />    
<bean id="bookValidator" class="library.validator.BookValidator" />     

<!-- Spring ViewResolver. -->               
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
         <value>/WEB-INF/jsp/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>   

<!-- Spring MesssageSource. -->         
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename"> 
        <value>/WEB-INF/classes/messages</value>    
    </property>    
</bean>

<!-- Spring Properties file for Library. -->      
<bean id="propertiesFactory" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="location">  
         <value>classpath:library.properties</value>             
    </property>
</bean>      

<!-- Hibernate DataSource. -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">   
    <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />        
    <!--property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" /-->
    <property name="url" value="jdbc:derby://localhost:1527/Library" />
    <property name="username" value="username" />
    <property name="password" value="password" />            
</bean>   

<!-- Hibernate Interceptors. -->
<bean id="serverInterceptor" class="library.interceptor.ServerInterceptor" />

<!-- Hibernate SessionFactory. -->    
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">    
    <property name="dataSource" ref="dataSource"></property>                  
    <property name="hibernateProperties">
        <props>    
           <prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop>                     
           <!--prop key="hibernate.dialect">org.hibernate.dialect.DerbyTenSixDialect</prop-->
           <prop key="hibernate.show_sql">false</prop>               

           <!-- What to do with the database schema. -->
           <prop key="hbm2ddl.auto">validate</prop>    
           <!-- 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. -->                 
        </props>            
    </property>                                                                                                                                
    <property name="entityInterceptor">
        <ref bean="serverInterceptor" />            
    </property>                                                                                                                                             
    <property name="packagesToScan">
        <list>
            <value>library.model</value>                
        </list>
    </property>          
</bean>

<!-- Hibernate TransactionManagment. -->
<tx:annotation-driven />                
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
   <property name="sessionFactory" ref="sessionFactory" />
</bean>  

And the errors given when the application builds and fails in the one environment is:

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

Which is then causing the wiring of the dependencies to fail.

What do these messages mean?

The application is using Spring 4.0.2 with hibernate-core-4.3.10.jar. All dependencies are identical between the three environments and a listing of them follows:

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

Aucun commentaire:

Enregistrer un commentaire