title: Tomcat deployment of application with HSQLDB database giving JDBCConnectionException
body: <p>I'm having a struggle with my first attempt with little application based on Spring, Hibernate on HSQLDB and JSF, finally deployed with Tomcat. I face two problems now.</p>
  
  <p>First of all I tried to run Java Application on console based on <code>main (String args[])</code> method getting <code>customerBo</code> bean from <code>spring-module.xml</code> and insert/delete from embedded HSQLDB with Hibernate. Works like a charm.</p>
  
  <p><strong>1. Two configuration locations</strong></p>
  
  <p>Another step was a JSF page printing out a sample bean content. Working as well. However I had a struggle with resources and configuration:</p>
  
  <ul>
  <li><p><strong>resources</strong>: Here is all my configuration for database.</p>
  
  <pre><code>src/main/resources
     \____ config
             \____ database
                       \____ database.properties
             \____ spring/beans    
                       \____ data-source.xml
                       \____ hibernate-session-factory.xml
     \____ spring-module.xml                            ... for Java Console Application
  </code></pre></li>
  <li><p><strong>webapp</strong>: Here is all related to JSF including <code>WEB-INF</code> folder` related to web-page alike application.</p>
  
  <pre><code>src/main/webapp
     \___ WEB-INF
             \____ applicationContext.xml                        ... for web application
             \____ faces-config.xml
             \____ web.xml
     \___ default.xhtml
  </code></pre></li>
  </ul>
  
  <p>How to make them easily communicate with each other? If web application starts from applicationContext in <strong>webapp</strong>, it needs to work with databse saved in <strong>resources</strong>. So it forces me to prefix all imports etc. with <code>classpath</code> such as.</p>
  
  <pre><code>&lt;import resource="classpath:/spring-module.xml"/&gt; 
  ... or ... 
  &lt;property name="location"&gt;
          &lt;value&gt;classpath:/config/database/database.properties&lt;/value&gt;
  &lt;/property&gt;
  </code></pre>
  
  <p>Java Console application still works well with these decors. Would you suggest me a better way? I import to <code>applicationContext.xml</code> all the database-stuff stored int <code>spring-module.xml</code>:</p>
  
  <pre><code>&lt;beans xmlns=....&gt;
      &lt;import resource="classpath:/spring-module.xml"/&gt;
      &lt;import resource="classpath:/bean.xml"/&gt;
  
      &lt;bean id="customerBo" class="nch.spring.customer.bo.impl.CustomerBoImpl"&gt;&lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>This is the URL I use to connect to HSQLDB</p>
  
  <pre><code>jdbc.url=jdbc:hsqldb:database/customers
  </code></pre>
  
  <p><strong>2. HSQLDB on Tomcat</strong></p>
  
  <p>I deploy on Tomcat externally, not in IDE. I run <code>localhost:8080</code>.</p>
  
  <p>After injecting all beans (working well, because I tested it on console), I recieved an error on Tomcat. Here is the shortened version with the first lines of causing:</p>
  
  <blockquote>
    <p>org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection</p>
    
    <p>Caused by: org.hibernate.exception.JDBCConnectionException: Could not open connection
    Caused by: java.sql.SQLException: No suitable driver found for jdbc:hsqldb:database/customers</p>
  </blockquote>
  
  <p>My database location related to project. It's included in the WAR:</p>
  
  <pre><code>project
      \____ src/main/java
      \____ src/main/resources
      \____ src/main/webapp
      \____ database
              \____ customers
                         \____ customers.script
                         \____ customers.lck
                         \____ customers.properties
  </code></pre>
  
  <p>And my pom.xml for HSQLDB:</p>
  
  <pre><code>&lt;!-- HSQLDB --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
      &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
      &lt;version&gt;2.3.2&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Why I cannot print out the database content with Spring and Hibernate on JSF deployed on Tomcat, but I can print it out on console? Is there an another way to embed a database? Does Tomcat support HSQLDB at all?  I have tried to work first with MySQL, but it had been so cumbersome for me.</p>
  
  <hr>
  
  <p>Shortly:</p>
  
  <ul>
  <li>HSQLDB works with Spring and Hibernate well, proved on Java Console Application. </li>
  <li>JSF pages working as well, able to print out the content of any bean. </li>
  </ul>
  
  <p>My application refuses to communicate with database since deployed on Tomcat. Here is my full source code on <a href="https://github.com/NicharCZ/07_jsf_hibernate" rel="nofollow">GitHub</a>.</p>