Here's our setup() - creates the db from scratch using schemaExport:
public void setUp() throws Exception {
super.setUp();
Properties properties = new Properties();
properties.load(new FileInputStream(getPropertiesFile()));
configuration = new Configuration();
configuration.addDirectory(getConfigurationDirectory());
configuration.setProperties(properties);
m_bInitDb = Boolean.valueOf(properties.getProperty(
"db.initialize", "true")).booleanValue();
if (m_bInitDb) {
final SchemaExport schemaExport = new SchemaExport(configuration,
properties);
schemaExport.setDelimiter(";");
schemaExport.create(true, true);
}
sessionFactory = configuration.buildSessionFactory();
}
Of course, this just creates empty tables; if you want data you'll need to add it!
We often use hypersonic sql db for junit testing, which supports an in-memory db, great for this purpose.
|