[
eivindw
]
16:19, Thursday, 21 October 2004
Been setting up hsqldb to use for development in a Spring/Hibernate/WebWork2 environment. What we want is to use schemaexport, middlegen, dbunit etc. to use a generated hsqldb stored in files under the target/ directory. The web app should get a separate copy of the database included in the war file.
We solved the problem as follows (with 'templatedb' sample db):
SchemaExport and other goals use the database with a file url:
...
hibernate.connection.url=jdbc:hsqldb:target/hsqldb/templatedb
...
This way we get the database generated under the target/hsqldb directory.
Added the following goals to maven.xml, to build a jar file from the hsqldb files:
<!-- add hsqldb jar to war file -->
<postGoal name="war:webapp">
<attainGoal name="hsqldbjar"/>
</postGoal>
<!-- goal to create hsqldb jar file -->
<goal name="hsqldbjar">
<jar
destfile="${maven.build.dir}/${pom.artifactId}/WEB-INF/lib/${pom.artifactId}db.jar"
basedir="${maven.build.dir}"
includes="hsqldb/**"/>
</goal>
This way the Spring application can use the database url with the new res: protocol:
jdbc:hsqldb:res:/hsqldb/templatedb
This is also superb for integration test cases. The database is cleaned out automatically for every testrun :)