eclipse-ee4j / eclipse-ee4j/jersey
Unable to rollback database transaction
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
I have developed application using Jersey 2.22.1, Hibernate and spring. Everthing is working fine for application however, I am using unit test for jersey framework and it seems also working fine to me. However, I am unable to rollback database transaction. My code is as follow and I am not getting any error just transaction is not rolling back.
@ContextConfiguration(locations =
{"classpath*:/META-INF/spring/applicationContext.xml"}
)
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners(TransactionalTestExecutionListener.class)
@Transactional
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public class TestingJerseyTest extends JerseyTest {
public class ResourceRegister extends ResourceConfig {
public ResourceRegister ()
{ // this is testing resoruce which is in different package. No problem in registering this. register(TestingResource.class); }
}
@Override
protected TestContainerFactory getTestContainerFactory()
{ return new GrizzlyWebTestContainerFactory(); }
@Override
protected DeploymentContext configureDeployment()
{ return ServletDeploymentContext .forServlet(new ServletContainer(new ResourceRegister())) .addListener(ContextLoaderListener.class) .contextParam("contextConfigLocation", "classpath*:/META-INF/spring/applicationContext.xml") .build(); }
// @Override
// protected Application configure()
{ // return new ResourceConfig(HelloResource.class); // }
@Path("hello")
public static class HelloResource {
@GET
public String getHello()
{ return "Hello World!"; }
}
@Test
public void test()
{ TransactionAspectSupport.currentTransactionStatus( ).setRollbackOnly(); // this is jaxb version of xml, getting no problem in transforming. Picture pictureXml = new Picture (); pictureXml .setId(66063); pictureXml .setNo(1253); target("pictures/picId").request(MediaType.APPLICATION_XML).post(Entity.xml(pictureXml )); // ignore next assert as this is just for testing main thing is that transaction is not roll backed after sending the post request. Actually, post request is handled be TestingResource.java and its working fine. Assert.assertEquals("Hello World!", "Hello World!"); }
}
#### Environment
Windows, Spring Software Tool Kit (Eclipse), Intel Core(TM) i5-3230 CPU @ 2.60 Ghz, 8GB RAM, 64 bit windows 8 operating system, JDK 1.8.45, Jersey version 2.22.1, Spring version, 4.1.9, Hibernate version 4.3.11.Final, Tomcat 8.0.23
#### Affected Versions
[2.22.1]
Contributor guide
Assessment
This issue has not been assessed yet.