liveBook · Manning

HSQLDB

As explained in Test Driven: Practical TDD and Acceptance TDD for Java Developers

HSQLDB is an open-source relational database management system written in Java that supports embedded and server modes.

An in-memory HSQLDB database gives DAO integration tests a lightweight alternative to contacting a slow remote or production database. With Hibernate, test-specific properties can override production connection settings. section 6.4.1

A test configuration specifies the connection details and database behavior:

  • Choose the HSQLDB SQL dialect and JDBC driver, then set the URL to jdbc:hsqldb:mem:testdb. section 6.4.1
  • Set the database username and password; enable hibernate.show_sql to print generated SQL while tests run. section 6.4.1
  • Use hibernate.hbm2ddl.auto=create-drop to create and remove the schema for the test database. section 6.4.1
Listing 6.16. Hibernate configuration file for an in-memory HSQLDB
hibernate.dialect=org.hibernate.dialect.HSQLDialect hibernate.connection.driver_class=org.hsqldb.jdbcDriver hibernate.connection.url=jdbc:hsqldb:mem:testdb hibernate.connection.username=sa hibernate.connection.password= hibernate.show_sql=true hibernate.hbm2ddl.auto=create-drop

See the complete Hibernate properties listing for an in-memory HSQLDB database. section 6.4.1

How Test Driven: Practical TDD and Acceptance TDD for Java Developers covers it

How deep it goes
Configures an in-memory test database through Hibernate properties, without detailing HSQLDB internals.
Examples
Uses jdbc:hsqldb:mem:testdb and a Hibernate properties file with SQL logging and create-drop schema handling.
What you can do after
Configure Hibernate to connect tests to a fresh in-memory HSQLDB database and print generated SQL.
How it connects
Connects Hibernate configuration and JDBC settings to DAO integration testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Test Driven: Practical TDD and Acceptance TDD for Java Developers. The section links point to the parts of the book it draws on.