title: Jpa testing and automatic rollback with Spring
body: <p>I am in reference to Spring Roo In Action (book from Manning). Somewhere in the book it says "Roo marks the test class as <code>@Transactional</code> so that <strong>the unit tests automatically roll back any change</strong>.</p>
  
  <p>Here is the illustrating method:</p>
  
  <pre><code>@Test
  @Transactional
    public void addAndFetchCourseViaRepo() {
      Course c = new Course();
      c.setCourseType(CourseTypeEnum.CONTINUING_EDUCATION);
      c.setName("Stand-up Comedy");
      c.setDescription(
        "You'll laugh, you'll cry, it will become a part of you.");
      c.setMaxiumumCapacity(10);
  
      c.persist();
      c.flush();
      c.clear();  
      Assert.assertNotNull(c.getId());
  
      Course c2 = Course.findCourse(c.getId());
      Assert.assertNotNull(c2);
      Assert.assertEquals(c.getName(), c2.getName());
      Assert.assertEquals(c2.getDescription(), c.getDescription());
      Assert.assertEquals(
        c.getMaxiumumCapacity(), c2.getMaxiumumCapacity());
      Assert.assertEquals(c.getCourseType(), c2.getCourseType());
    }
  </code></pre>
  
  <p>However, I don't understand why changes in this method would be automatically rolled back if no RuntimeException occurs...</p>