Have not tried this but it should work. It should be possible to inject a TestDataInjector object into the Test class. You should setup this class in a separate test-context file.
However, this does not "Feel good" to me, your data will be persisted to the database and unless you are using an in-memory database you have to manually remove it. Why not setup in the same transaction?
Code:
class TestDataInjector {
@PersistenceContext
private EntityManager entityManager;
public void inject() {// do stuff}
}
Code:
class MyTestClass extends AbstractJpaTests {
public void setTestDataInjector(TestDataInjector injector) {}
public void onSetUpInTransaction() {
setDefaultRollback(false);
endTranscation();
startNewTransaction();
injector.inject();
endTransaction();
setDefaultRollback(false);
}
}