Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7507065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:24:39+00:00 2026-05-29T22:24:39+00:00

I am using Spring’s embedded-database (default DB is HSQLDB) for running some unit tests.

  • 0

I am using Spring’s embedded-database (default DB is HSQLDB) for running some unit tests. I have the following in my context:

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManger">
    <property name="dataSource" ref="dataSource"/>
</bean>

<jdbc:embedded-database id="dataSource">
   <jdbc:script location="blah"/>
</jdbc:embedded-database>

The unit test is as such:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
@TransactionConfiguration(transactionManager="transactionManager", defaultRollback=true)
@Transactional
public class DAOTest(){

   @Autowired
   public MyDAO myDAO;


   @Test
   public void test1(){
      List list = myDAO.getHibernateTemplate.loadAll(Hit.class);
      assertThat(list.size(), equalTo(0));

      Hit hit = new Hit();
      myDAO.saveHit(hit);

      list = myDAO.getHibernateTemplate.loadAll(Hit.class);
      assertThat(list.size(), equalTo(1));
   }

   @Test
   public void test2(){

      List list = myDAO.getHibernateTemplate.loadAll(Hit.class);
      assertThat(list.size(), equalTo(0));
   }

}

When I run the above, test 2 fails because a list with 1 element is returned. Why is the rollback not happening between the tests?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:24:40+00:00Added an answer on May 29, 2026 at 10:24 pm

    So figured it out. The problem was that I was using a DataSourceTransactionManager but was using Hibernate in the code and therefore needed to use a HibernateTransactionManager.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Spring.net with NHiberante (HibernateTemplate) to implement my DAO's. I also have some
I'm using Spring 2.5.6. I have a bean whose properties are being assign from
I am using Spring 3.0.2. I have two relatively simple bean definitions. One has
I am using Spring 3.0 with Hibernate and PostgreSQL and I have following problem:
Using Spring 3.0.x, I'm running into an issue where a Bean init-method is running,
Using Spring 2.5 tag library, I have an Integer value in a command form
I've been using spring for some time, but I always wondered how does it
We have started using Spring framework in my project. After becoming acquainted with the
Using: Spring 3.1.0.RELEASE, Spring Data MongoDB 1.0.0.RELEASE I have a document class defined like
Using Spring 3 I have two forms: adding Item and invalidating Item I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.