Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

363
Views
@Rollback is not working in Spring+Hibernate+Junit testing

while testing a DAO function in spring+hibernate application, data rollback is not happening. I am trying to do the rollback a junit test case by @Rollback annotation

transactionManager config:

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="emf" />
</bean>

In my main code I am using hibernateTemplate() to do CRUD operations

test code:

@Test
@Transactional
@Rollback(true)
public void test_populateObject() throws Exception {


    // TransactionDefinition def = new DefaultTransactionDefinition();
    // TransactionStatus status = transactionManager.getTransaction(def);

    manualObj= new ManualObj();

    manualObj.setName("TestObj001");
    manualObj.setRefId("TestObj001");
    manualObj.setCallback("TestObj001");
    m
    TestObject obj=orderService.createTestObject(manualObj);

    Assert.assertNotNull(obj);

    // transactionManager.rollback(status);

}

The created object is not being deleted by rollback.

So, What could be the reason that @Rollback is n't happening?

Edit 1:

I am using Spring Data JPA and hibernateTemplate based data access in same application. Both using the same transaction manager specified like the above bean config.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Did you configure your test to use the xml configuration, and did you specify the SpringJUnit4ClassRunner to run your test? You can do it like this:

@RunWith(SpringJUnit4ClassRunner.class)  
@ContextConfiguration(locations = {"testContext.xml"})
@Transactional
public class YourTest{ ... }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!