3
私はTestNG + Spring + Hibernateを使用します。私は@BeforeClassでトランザクションを使用する場合 は、私が取得:TestNG @BeforeClassでトランザクションをどのように使用できますか?
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
コード例:
@Transactional(transactionManager = "transactionManager")
@Rollback
@ContextConfiguration(locations = "/WEB-INF/testing/applicationTestContext.xml")
@TestExecutionListeners(listeners = {
ServletTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
TransactionalTestExecutionListener.class,
SqlScriptsTestExecutionListener.class,
WithSecurityContextTestExecutionListener.class
})
public abstract class ExampleOfTest extends AbstractTestNGSpringContextTests{
@Autowired
private SessionFactory sessionFactory;
@BeforeClass
public void setUpClass() {
sessionFactory.getCurrentSession().beginTransaction(); // get HibernateException
sessionFactory.getCurrentSession().getTransaction().commit();
}
....
}
私は@BeforeClassでトランザクションを使用することができますどのように? すべてのクラステストで使用される1回限りのデータ入力にこれを使用したいと思います。