Convenient support class for JPA-related tests. Offers the same contract as
AbstractTransactionalDataSourceSpringContextTests and equally good performance,
even when performing the instrumentation required by the JPA specification.
Exposes an EntityManagerFactory and a shared EntityManager.
Requires an EntityManagerFactory to be injected, plus the DataSource and
JpaTransactionManager through the superclass.
When using Xerces, make sure a post 2.0.2 version is available on the classpath
to avoid a critical
bug
that leads to StackOverflow. Maven users are likely to encounter this problem since
2.0.2 is used by default.
A workaround is to explicitly specify the Xerces version inside the Maven pom:
createContainerManagedEntityManager()
Create an EntityManager that will always automatically enlist itself in current
transactions, in contrast to an EntityManager returned by
EntityManagerFactory.createEntityManager()
(which requires an explicit joinTransaction() call).
createShadowingClassLoader(ClassLoader classLoader)
NB: This method must not have a return type of ShadowingClassLoader as that would cause that
class to be loaded eagerly when this test case loads, creating verify errors at runtime.
Create an EntityManager that will always automatically enlist itself in current
transactions, in contrast to an EntityManager returned by
EntityManagerFactory.createEntityManager()
(which requires an explicit joinTransaction() call).
shouldUseShadowLoader
protected boolean shouldUseShadowLoader()
Subclasses should override this method if they wish
to disable shadow class loading. Do this only
if instrumentation is not required in your
JPA implementation.
Called to say that the "applicationContext" instance variable is dirty and
should be reloaded. We need to do this if a test has modified the context
(for example, by replacing a bean definition).
NB: This method must not have a return type of ShadowingClassLoader as that would cause that
class to be loaded eagerly when this test case loads, creating verify errors at runtime.
shadowingClassLoader - this parameter is actually of type
ResourceOverridingShadowingClassLoader, and can safely to be cast to
that type. However, the signature must not be of that type as that
would cause the present class loader to load that type.