title: Commit/Flush transactions during unit test?
body: <p>I am using Spring and JUnit to write some integration tests for my DAO. I set up my test data in the beginning of the test method, and then test my DAO methods later in the same test method. The problem is that if I don't flush/commit the transaction, the EntityManager returns the same instance of the entities that I have just created in my data setup - rendering my test useless as they will always pass.</p>
  
  <p>E.g.</p>
  
  <pre><code>@Test   
  @Transactional()
  public void loadTreeBasicCase() {
      // creates and saved node to DB
      Node n = createNode();
  
      // test DAO
      Node result = dao.lookup(n.getId());
  
      // verify
      assertThat(n, equalTo(result));
  }
  </code></pre>
  
  <p>One way is to expose commit() and/or flush() methods in my DAO. But I would prefer not to do that because in production code, this almost never needs to happen (let EntityManager do it's thing). Is there a way to configure this via annotations or in Spring config? I am using Spring, JPA2 with Hibernate.</p>