Hibernate + HSqlDb in-memory testing
Hi, Srini
I have been doing a little bit of testing using in-memory databases with Hibernate. The code creates a new database per test. It runs reasonably fast, as it uses Hypersonic SQL in-memory:
Code:
private SessionFactory sessionFactory;
public void setUp() throws Exception {
Configuration config = new Configuration();
config.setProperty("hibernate.connection.driver_class", jdbcDriver.class.getName());
config.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:persistentTest");
config.setProperty("hibernate.dialect", HSQLDialect.class.getName());
config.addClass(TestClass.class);
SchemaExport export = new SchemaExport(config);
export.create(true, true);
this.sessionFactory = config.buildSessionFactory();
}
If using Hibernate is not an option, you can try creating a seed database and loading it with HSQLDB's :res: URL. See my blog for a more thourough analysis.
~Johannes