title: Converting MySQL to H2
body: <p>I’m working on a project following this code : 
  Link to download of code: <a href="https://bitbucket.org/vrto/spring-tutorial/get/a66534cc7033.zip" rel="nofollow">https://bitbucket.org/vrto/spring-tutorial/get/a66534cc7033.zip</a></p>
  
  <p>Now what I really want, instead of MySQL, is to have an embedded database running HSQL or H2. So I’ve working on my own project trying to implement such a system.</p>
  
  <p>In the tutorial code, he creates a database. And then h2 + hibernates creates the future tables for him – so it would be create if I could do this without having to have an sql schema or anything to set it up. 
   So I’ve gotten rid of mySql maven dependencies and am working on replacing the persistence-beans.xml
  Now I have to replace my dataSource with a relevant h2 or hsql version.
  So this is what I’ve gotten.</p>
  
  <pre><code>&lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close"&gt;
      &lt;property name ="driverClassName" value = "org.h2.driver"/&gt;
      &lt;property name = "url" value ="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1" /&gt;
      &lt;property name = "username" value = "sa" /&gt;
      &lt;property name = "password" value = "" /&gt; 
  &lt;/bean&gt;
  
  // I also tried this (but again, having a schema with his code is tricky I’ve found
  
  &lt;jdbc:embedded-database id="dataSource" type="H2"&gt;
      &lt;jdbc:script location="classpath:schema.sql"/&gt;
      &lt;jdbc:script location="classpath:test-data.sql"/&gt;
  &lt;/jdbc:embedded-database&gt;
  </code></pre>
  
  <p>But it fails upon running HibernateConfigurationTest.Java (and in extension – all the others)
  Any help would be greatly appreciated.</p>
  
  <p>I've managed to get this test work with my schema </p>
  
  <pre><code>@ContextConfiguration(locations = "/persistence-beans.xml")
  public class HibernateConfigurationTest extends AbstractJUnit4SpringContextTests {
  
      @Autowired
      private SessionFactory sessionFactory;
  
      @Test
      public void testHibernateConfiguration() {
          // Spring IOC container instantiated and prepared sessionFactory
          assertNotNull (sessionFactory); 
      }
  
  }
  </code></pre>
  
  <p>the rest tests are in this link : <a href="http://vrtoonjava.wordpress.com/2012/06/17/part-3-dao-and-service-layer/" rel="nofollow">http://vrtoonjava.wordpress.com/2012/06/17/part-3-dao-and-service-layer/</a></p>