title: Declarative spring transactions not being committed
body: <p>I have the following service classes:</p>
  
  <pre><code>public class UserLoginServiceImpl implements UserLoginService {
  
    private UserDAO dao;
  
    public UserLoginServiceImpl(UserDAO dao) {this.dao = dao; }
  
    public User login(String userName, String password) {
       User u = dao.findUserByCredentials(userName, password);
       if (u == null) {
           throw new UserNotFoundException();
       }
       return u;
  }
  
  public class UserManagementServiceImpl implements UserManagementService {
  
    private UserDAO dao;
  
    public UserManagementServiceImpl(UserDAO dao) { this.dao = dao; }
  
    public void createUser(User u) {
       dao.save(u);
    }
  }
  </code></pre>
  
  <p>My service interfaces reside under <em>com.mysystem.services</em> package and my service implementations under <em>com.mysystem.services.impl</em> package.</p>
  
  <p>I am using hibernate as my jpa implementation and declarative transactions in spring. My configuration file is the following:</p>
  
  <p>
  
    
      </p>
  
  <pre><code>&lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
  &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
  &lt;/bean&gt;
  
  &lt;tx:advice id="txAdvice" transaction-manager="transactionManager"&gt;
      &lt;tx:attributes&gt;
          &lt;tx:method name="*"/&gt;
      &lt;/tx:attributes&gt;
  &lt;/tx:advice&gt;
  
  &lt;aop:config&gt;
      &lt;aop:pointcut id="serviceMethod" expression="execution(* com.mysystem.services.impl.*.*(..))"/&gt;
      &lt;aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"/&gt;
  &lt;/aop:config&gt;
  
  &lt;!--
      Beans
   --&gt;
  &lt;bean id="userDao" class="com.mysystem.dao.UserDAOImpl"&gt;
      &lt;constructor-arg ref="entityManagerFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="userLoginService" class="com.mysystem.services.impl.UserLoginServiceImpl"&gt;
      &lt;constructor-arg ref="userDao" /&gt;
  &lt;/bean&gt;
  &lt;bean id="userManagementService" class="com.mysystem.services.impl.UserManagementServiceImpl"&gt;
      &lt;constructor-arg ref="userDao" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Lastly, somewhere in my code i run the following:</p>
  
  <pre><code>UserManagementService userManagementService = context.getBean(UserManagementService.class);
  userManagementService.createUser(new User("test", "test"));
  
  UserLoginService userLogginService = context.getBean(UserLoginService.class);
  User user = userLogginService.login("test", "test");
  </code></pre>
  
  <p>which results in the <em>login()</em> method throwing an <em>UserNotFoundException</em> because it cannot find the user inserted by <em>createUser()</em> previously which means that hibernate will not flush the session between method calls. I can verify this form the console output (i can see hibernate's <em>create</em> and <em>select</em> statements but not <em>insert</em>).</p>
  
  <p>Why isn't the transaction committed soon after the call to <em>createUser()</em>? What am i doing wrong here?</p>
  
  <p>EDIT:</p>
  
  <p>Using the @Transactional annotation instead of declarative transactions works. Using @Transactional however is not an option for me. I need to implement declarative transactions.</p>
  
  <p>Below is the spring's debug output:</p>
  
  <pre><code>13:03:18,174 DEBUG [main] jpa.JpaTransactionManager     - Creating new transaction with name [com.mysystem.services.impl.UserManagementServiceImpl.createUser]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT
  13:03:18,175 DEBUG [main] jpa.JpaTransactionManager     - Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@1af6a711] for JPA transaction
  Hibernate: 
      select
          nextval ('hibernate_sequence')
  13:03:18,255 DEBUG [main] jpa.JpaTransactionManager     - Initiating transaction commit
  13:03:18,255 DEBUG [main] jpa.JpaTransactionManager     - Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@1af6a711]
  13:03:18,256 DEBUG [main] jpa.JpaTransactionManager     - Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@1af6a711] after transaction
  
      13:03:18,263 DEBUG [main] jpa.JpaTransactionManager     - Creating new transaction with name [com.mysystem.services.impl.UserLoginServiceImpl.login]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT
      13:03:18,263 DEBUG [main] jpa.JpaTransactionManager     - Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@1533badd] for JPA transaction
      Hibernate: 
          /* 
      from
          com.mysystem.domain.User u 
      where
          u.userName = :userName 
          and u.password = :password */ select
              user0_.id as id0_,
              user0_.password as password0_,
              user0_.userName as userName0_ 
          from
              Users user0_ 
          where
              user0_.userName=? 
              and user0_.password=? limit ?
      13:03:18,374 TRACE [main] sql.BasicBinder     - binding parameter [1] as [VARCHAR] - test
      13:03:18,374 TRACE [main] sql.BasicBinder     - binding parameter [2] as [VARCHAR] - test
      13:03:18,379 DEBUG [main] jpa.JpaTransactionManager     - Initiating transaction commit
      13:03:18,379 DEBUG [main] jpa.JpaTransactionManager     - Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@1533badd]
      13:03:18,379 DEBUG [main] jpa.JpaTransactionManager     - Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@1533badd] after transaction
  </code></pre>