public abstract class

AbstractJpaTests

extends AbstractAnnotationAwareTransactionalTests
java.lang.Object
   ↳ junit.framework.Assert
     ↳ junit.framework.TestCase
       ↳ org.springframework.test.ConditionalTestCase
         ↳ org.springframework.test.AbstractSpringContextTests
           ↳ org.springframework.test.AbstractSingleSpringContextTests
             ↳ org.springframework.test.AbstractDependencyInjectionSpringContextTests
               ↳ org.springframework.test.AbstractTransactionalSpringContextTests
                 ↳ org.springframework.test.AbstractTransactionalDataSourceSpringContextTests
                   ↳ org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests
                     ↳ org.springframework.test.jpa.AbstractJpaTests
Known Direct Subclasses

This class is deprecated.
as of Spring 3.0, in favor of using the listener-based test context framework (AbstractJUnit38SpringContextTests)

Class Overview

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:

 <dependency>
   <groupId>xerces</groupId>
     <artifactId>xercesImpl</artifactId>
   <version>2.8.1</version>
 </dependency>
 

Summary

[Expand]
Inherited Constants
From class org.springframework.test.AbstractDependencyInjectionSpringContextTests
Fields
protected EntityManagerFactory entityManagerFactory
protected EntityManager sharedEntityManager Subclasses can use this in test cases.
[Expand]
Inherited Fields
From class org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests
From class org.springframework.test.AbstractTransactionalDataSourceSpringContextTests
From class org.springframework.test.AbstractTransactionalSpringContextTests
From class org.springframework.test.AbstractSingleSpringContextTests
From class org.springframework.test.ConditionalTestCase
Public Constructors
AbstractJpaTests()
Public Methods
void runBare()
Overridden to populate transaction definition from annotations.
void setDirty()
Called to say that the "applicationContext" instance variable is dirty and should be reloaded.
void setEntityManagerFactory(EntityManagerFactory entityManagerFactory)
Protected Methods
String cacheKeys()
EntityManager 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).
ClassLoader 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.
void customizeResourceOverridingShadowingClassLoader(ClassLoader shadowingClassLoader)
Customize the shadowing class loader.
String getActualOrmXmlLocation()
Subclasses can override this to return the real location path for orm.xml or null if they do not wish to find any orm.xml
boolean shouldUseShadowLoader()
Subclasses should override this method if they wish to disable shadow class loading.
[Expand]
Inherited Methods
From class org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests
From class org.springframework.test.AbstractTransactionalDataSourceSpringContextTests
From class org.springframework.test.AbstractTransactionalSpringContextTests
From class org.springframework.test.AbstractDependencyInjectionSpringContextTests
From class org.springframework.test.AbstractSingleSpringContextTests
From class org.springframework.test.AbstractSpringContextTests
From class org.springframework.test.ConditionalTestCase
From class junit.framework.TestCase
From class junit.framework.Assert
From class java.lang.Object
From interface junit.framework.Test

Fields

protected EntityManagerFactory entityManagerFactory

protected EntityManager sharedEntityManager

Subclasses can use this in test cases. It will participate in any current transaction.

Public Constructors

public AbstractJpaTests ()

Public Methods

public void runBare ()

Overridden to populate transaction definition from annotations.

Throws
Throwable

public void setDirty ()

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).

public void setEntityManagerFactory (EntityManagerFactory entityManagerFactory)

Protected Methods

protected String cacheKeys ()

protected EntityManager 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).

protected ClassLoader 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.

protected void customizeResourceOverridingShadowingClassLoader (ClassLoader shadowingClassLoader)

Customize the shadowing class loader.

Parameters
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.

protected String getActualOrmXmlLocation ()

Subclasses can override this to return the real location path for orm.xml or null if they do not wish to find any orm.xml

Returns
  • orm.xml path or null to hide any such file

protected boolean shouldUseShadowLoader ()

Subclasses should override this method if they wish to disable shadow class loading.

The default implementation deactivates shadow class loading if Spring's InstrumentationSavingAgent has been configured on VM startup.