I have a scenario that I have to assume is fairly commonplace.

Following the instructions on the OpenEJB site, I've got a local OpenEJB
server running for my unit tests.  I park the thing on top of an in-memory
H2 database.  All fine and good.

What I'd like to do is this:

   - Wipe the database entirely between tests
   - Cause the embedded OpenJPA to redo any configured DDL generation before
   each test

Note that I'm not looking for what DBUnit does, namely resetting the
database for you.  I want the JPA provider to take care of the DDL
generation for me.

Is there any way to do this?  H2 helps, somewhat, in that you can open up an
in-memory only database that will disappear when the last connection to it
is closed.  If I could get my grubby paws on the container-supplied entity
manager factory at some sort of global level and tell it to reinitialize
itself, then I could put that code at the beginning of each JUnit test.
This should close all the connections in the OpenJPA connection pool, I'd
think, thus wiping the H2 database; and would also, by virtue of
reinitializing the EntityManagerFactory, cause the DDL generation to fire
again.  The net result is that all my EJBs under test would be initialized
with a blank database in between tests.

I hope I'm making sense.  Does anyone have a recipe for doing this?

Thanks,
Laird

Reply via email to