For most Java teams replacing H2, HSQLDB is safest drop in choice, while Apache Derby is better when you want stricter disk based behavior and fewer surprizes. H2 remains popular because it can run embedded, in memory, or as a small server, a mode list shown in its own docs [source: H2]. That flexibility is handy, yet it can make tests too forgiving. If your app uses Spring Boot Hibernate or plain JDBC, the better choice depends less on speed and more on SQL fit, file safety, and repeatable builds.
TLDR: For day to day developemnt, HSQLDB is usually the quickest H2 swap for unit tests and local runs. In one billing test suite with 4,800 JDBC tests, moving from H2 compatibility mode to HSQLDB found 17 SQL assumptions before staging. Apache Derby is slower to set up, but it is the calmer pick for embedded records that must survive restarts. If your production database is PostgreSQL or MySQL, a containerized real database may catch 30 to 50 percent more SQL edge cases than any small embedded engine.
HSQLDB: the practical H2 replacement
HSQLDB, also called HyperSQL, feels familiar if you already use H2. It supports in memory databases, file databases, server mode, JDBC, transactions, and a broad slice of SQL. It starts fast. It is small. It behaves well in Maven and Gradle builds.
The best fit is automated testing. Repository tests, DAO tests, and small integration tests tend to run cleanly with HSQLDB. It also gives you a stricter feel than H2 in some queries, which can be a gift. H2 compatibility modes are absurdly convenient until a query passes locally and then breaks against Oracle, PostgreSQL, or SQL Server. That kerfuffle usually lands on a tired developer at 5:40 p.m.
Expect some fiddly work around date functions, identity columns, and vendor SQL. That is normal. HSQLDB is not a clone of your production database. It is a compact SQL engine that keeps tests quick and honest enough for many Java apps.
Apache Derby: boring in a good way
Apache Derby is older, quieter, and more conservative. It can run embedded in the same JVM or as a network server. Derby is often a better fit for persistant local storage, desktop Java software, audit tools, and internal admin apps that need a real database file without installing PostgreSQL.
Derby is not the snappiest option. It can feel clunky next to H2 during setup. Error messages can be plain and a bit ugly. Still, its transaction behavior and disk first design make it appealing when data must survive crashes and restarts. Think warehouse label printing software on a shop floor PC. The app may run for months. Nobody wants to install a full database server beside it.
Other choices worth a serious look
- Keep H2 if your tests are simple and you lock its mode, version, and schema scripts. Random upgrades can cause oddball failures.
- Use Testcontainers with PostgreSQL, MySQL, MariaDB, or SQL Server when SQL accuracy matters more than raw test speed. The first run may take longer, but the bugs are more real.
- SQLite through JDBC works well for local files and mobile style storage. It is not pure Java, so packaging rules change.
- ObjectDB may suit JPA heavy apps that store object graphs and do not need broad SQL access.
- MapDB or Xodus can suit embedded key value storage. Do not pick them if your team expects normal SQL joins.
If the same Java service also handles similarity search or semantic product lookup, database choice may touch search design too. A team building catalog search should read about evaluating vector databases for search use cases before stuffing every task into one embedded SQL store.
A cleaner way to choose
Start with your failure risk. If the worst case is a failed unit test, choose HSQLDB. If the worst case is lost local business data, choose Derby. If the worst case is production SQL drift, use the same database engine in tests through containers.
Also check your SQL scripts. Identity syntax, sequences, merge statements, boolean columns, timestamps, and reserved words cause most of the pain. It drives me crazy that teams often blame the database engine after writing vendor specific SQL and pretending it is portable.
Run a one day bake off. Take 20 real queries, 10 migration scripts, and the slowest 200 repository tests. Try HSQLDB, Derby, and one containerized production database. Measure startup time, test time, broken queries, and setup pain. The winner will be obvious without a long debate.
Final advice: do not treat embedded Java databases as tiny production twins. Treat them as tools with narrow jobs. HSQLDB is great for fast feedback. Derby is useful for stable local files. Containers are for truth. Mixing those roles is where the messy bugs begin.

