Reputation: 3353
In production, we use SQL scripts (Postgres) to generate / update the schema. In my unit tests, I use configProperties.put("hibernate.hbm2ddl.auto", "create-drop");
in order to create the schema for my H2 database.
In order to isolate the unit tests better, I want to drop and recreate the database in between tests. I can wipe the H2 database with entityManager.createNativeQuery("DROP ALL OBJECTS").executeUpdate();
, but how do I then get hibernate to re-create the schema?
Or is there an easy way to simply shut down H2 and create a new instance? I can create multiple instances by using "jdbc:h2:mem:"+UUID.randomUUID()+";MODE=DB2;"
as my connection string, but I'm not sure how to shut down / destroy / clean up previous instances.
Upvotes: 2
Views: 478