@Transaction annotated method does not save data into a database
<p>In my unit tests I want to persist some entities and test their retrieval from the database. They were not being saved and I figured out that when the test method was also annotated with <code>@Transaction</code>, anything that happened inside it did not get persisted, even though the method finished without an error.</p>

<p>I had previously encountered a <code>LazyInitializationException</code> when messing with a many-to-many lazy-loaded association and annotating the method with <code>@Transaction</code> seemed to fix the issue, that's why I have been using it. </p>

<p>What could be the cause why the entities don't get saved? There is no reason for the transaction to be rolled back, since it does not fail.</p>

<p><strong>Code of related classes:</strong></p>

<pre><code>@Test
@Transactional
public void plainPersistence() throws NullParameterException {
    User user = userHelper.createUser("User1", "password", null, null);

    Assert.assertNotNull(userDAO.findByUsername("User1"));
}
</code></pre>

<p>userHelper:</p>

<pre><code>@Service
public class UserHelper {
    @Autowired
    private UserDAO userDAO;


    public User createUser(...) throws NullParameterException {
        User newUser = new User(username, ...);

        userDAO.save(newUser);

        return newUser;
    }
</code></pre>

<p>UserDAO's <code>save()</code> method subsequently calls <code>save()</code> on <code>UserRepository</code>:</p>

<pre><code>@Repository
public interface UserRepository extends CrudRepository&lt;User, Long&gt; {
    public User findByUsername(String username);
}
</code></pre>