Spring 3 MVC Hibernate Hsqldb Embedded database

In this tutorial we will create simple Spring 3 MVC application with Hsqldb as embedded database.
We will start with project created in previuos tutorial, where we were using H2 database.

All we need to do is just add maven dependency:

<!-- HSQL -->
<dependency>
    <groupId>org.hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <version>2.3.2</version>
</dependency>

and tell Spring and Hibernate to use it:

<!-- Use in-memory embedded HSQL database -->
<jdbc:embedded-database id="dataSource" type="HSQL">
</jdbc:embedded-database>

<!-- Database managed by Hibernate -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="UsersPU" />
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" >
        <list>
            <value>com.devcases.usermanager.model</value>
        </list>
    </property>
    <property name="persistenceProvider">
        <bean class="org.hibernate.jpa.HibernatePersistenceProvider" />
    </property>
    <property name="jpaProperties">
        <map>
            <entry key="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
            <entry key="hibernate.hbm2ddl.auto" value="create" />
            <entry key="hibernate.hbm2ddl.import_files" value="import_data.sql" />
            <entry key="hibernate.show_sql" value="true" />
        </map>
    </property>
</bean>

<bean id="transactionManager"
        class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

The project sources can be downloaded here.

Leave a Reply

Your email address will not be published. Required fields are marked *