On Sat, Oct 3, 2009 at 12:07 PM, Quintin Beukes <quin...@skywalk.co.za>wrote:

> Yes,it is managed by the container and the context. The initial
> context will close with the VM. Afaik it will have the same behaviour
> after the test closes as the EJB would.


OK; good to know.

>From you e-mail I figure your focus is on the automatic destruction of
>
the db.


Yes.  H2, specifically.

I've *never* had luck with the DB being automatically destroyed between
tests.  I've closed the context, used the magic property (destroyOnClose?
don't remember offhand), tried setting up H2 without the DB_CLOSE_DELAY
setting, *with* the DB_CLOSE_DELAY setting--nothing.  It might have to do
with the strange intersection of (a) there being a connection pool and (b)
H2's being an in-memory database that tries to destroy itself when it thinks
it's safe to do so.

I can verify this because when I have two test methods that each try to
persist an object with the same ID--which would succeed in a blank
database--my second method fails.

To be clear, then, I want my named H2 database to be wiped out and
recreated--complete with DDL generation as described by my JPA
mappings--before each test method is run.

To put it one final way, I want my test code to look like this:
X x = new X();
this.em.persist(x);

...i.e. no beginning transactions, no shutting down databases, no mucking
about with EntityManagerFactories, etc. etc. etc.  Just bare bones
simplicity.  Frankly OpenEJB need not even be involved, but it seemed like
an easy black box that would enable most of these kinds of tests.

Thanks for getting involved,
Laird

Reply via email to