HSQL In-memory database hibernate maven config example

Reading Time: 1 minute

maven dependency

<properties>
        <!-- PROJECT DEPENDENCIES BEGIN -->
        <hsqldb.version>2.3.4</hsqldb.version>
        <!-- PROJECT DEPENDENCIES END -->
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>${hsqldb.version}</version>
        </dependency>
    </dependencies>

hibernate configuration

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.archive.autodetection">class,hbm</property>
        <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="hibernate.connection.username">sa</property>
        <property name="hibernate.connection.password">1</property>
        <property name="hibernate.connection.url">jdbc:hsqldb:mem:testdb</property>
        <property name="hibernate.hbm2ddl.auto">create</property>

        <mapping class="de.gameduell.entity.User" />
        <mapping class="de.gameduell.entity.Statistics" />
    </session-factory>
</hibernate-configuration>

Leave a Reply

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