I have just done the same, but I don't create a new datasource outside
the container. When you run code outside the container you have to use
another hibernate.cfg.xml where you specify driver_class, url, username
and password.
My hibernate.cfg.xml (for use in Tomcat) looks like this:
java:com
My suggestion would be to have a different hibernate configuraiton for
your tests. I have a base test class that creates a mock setup of
instances in a fresh test database and then run the tests against that
before cleaning up.
There are dummy JNDI implementations around though if you'd prefer th
What you could do is have multiple setups so that some junit tests use the
container, others use it from a differnet location. You may be able to use
a container (Look at spring or the Avalon wrapper) to handle this. Just
configure two copys of Hibernate depending on where you need your
datasour