H2 Database support for Alfresco

Jon Evans edited this page Jan 23, 2015 · 17 revisions
Clone this wiki locally

It's always desirable to use an embedded DB for unit/integration testing your application. Alfresco doesn't ship with any support for such databases by default, but it's still possible to leverage H2 compatibility mode along with the standard PostgreSQL database configuration to enable such a useful feature.

Current limitations

Upgrade scripts are not provided, you will have to recreate the database from scratch when upgrading your Alfresco version.

Alfresco Enterprise Support

Depending on the version of Alfresco you're targeting, you should use different versions of the H2 support module. The following are the currently tested versions of Alfresco Enterprise and the correspondent module versions. Alfresco Community is not officially supported, although there are high chances to find a h2-support version that works with your Alfresco Community edition (see below).

Since Alfresco 4.2.0, the intention is to keep the h2-support version in step with the Alfresco version.

Alfresco H2 support module
v5.0 v5.0
v4.2.1 v4.2.1
v4.2.0 v4.2.0
v4.1.6 v1.8
v4.1.5 v1.7
v4.1.4 v1.6
v4.1.1 v1.5
v4.0.2 v1.4
v4.0.1 v1.3
v4.0.0 v1.2
v3.4.12 v1.1.1
v3.4.0 v1.1

Alfresco community support

Although not officially supported, the following H2 Support and Alfresco Community versions are reported to be compatible

Alfresco H2 support module
v4.2.b v1.5
v4.0.d v1.2
v4.0.b v1.2

Usage scenario

If you have a custom AMP project created using the Maven Alfresco Archetypes it will directly use this module when running e.g. mvn integration-test -Pwebapp.

If you have a custom Alfresco WAR project, and you want to start it on a Jetty and make use of H2, you will need to:

  • add the following jetty-env.xml file to src/test/webapp:

     <?xml version="1.0"?>
     <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
     <Configure class="org.mortbay.jetty.webapp.WebAppContext">
         <New id="myDataSource"
                 <New class="org.h2.jdbcx.JdbcDataSource">
                     <Set name="URL">jdbc:h2:${alfresco.data.location}/h2_data/${alfresco.db.name};MVCC=true</Set>
                     <Set name="User">${alfresco.db.username}</Set>
                     <Set name="Password">${alfresco.db.password}</Set>
  • add the following snippet to your POM to start a jetty instance as part of the integration test phase on port 9090:

                          <!-- Runs jetty when 'integration-test' phase is called -->
                                      <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">