views:

155

answers:

2

My integration tests would run much faster if I used in-memory-database instead of PostgreSQL. I use JPA (Hibernate) and I need an in-memory-database that would be easy to switch to using JPA, easy to setup, and reliable. It needs to support JPA and Hibernate (or vice verse if you will) rather extensively since I have no desire to adopt my data access code for tests.

What database is the best choice given requirements above?

+3  A: 

I've been using HSQLDB in-memory for integration testing JPA/Hibernate persistence in Java. Starts pretty quickly, doesn't require any special setup.

The only issue I've seen so far with using HSQLDB with Hibernate was to do with batch size needing to be set to 0, but that might just have been related to an old version. I'll have a dig and see if I can find details of that problem.

It also appears that Derby supports an in-memory mode these days, however it is marked experimental...

Brabster
given equal support for in-memory-database I'd like to have the simplest and least invasive (hopefully zero customization (except for persistence.xml) solution). Thanks!
grigory
Another vote for HSQLDB, especially since the release of V2, v1.x wouldn't support some of the current constructs that are supported by JDBC, like returning autogenerated key values, but v2 does.
mezmo
+3  A: 

For integration testing, I now use H2 (from the original author of HSQLDB) that I prefer over HSQLDB. It is faster (and I want my tests to be as fast as possible), it has some nice features like the compatibility mode, the dev team is very responsive (while HSQLDB remained dormant for years until very recently).

Pascal Thivent
The benchmarks are for persistent data store, in-memory results maybe different since most of the overhead is due to disk/cache policies in the databases. The difference between H2 and HSQLDB is considerable but not critical. I'd still choose based on ease of use, minimal configuration, features. And the compatibility mode feature indeed looks very attractive. Thanks!
grigory
@grigory: Yes, you are right. But even when using a persistent mode, H2 and HSQLDB actually run in memory by default and defer writing to disk (at the price of Durability). So the data are still interesting.
Pascal Thivent