title: Hibernate and Spring Transaction Manager: Transaction Not Successfully Started
body: <p>I have a Generic Repository with a method named saveList(). The purpose of this method is to take a List and persist it in "chunks" of 500 objects. Unfortunately, I'm getting a "TransactionException: Transaction not successfully started" when I get to the commit.</p>
  
  <p>Everything I've seen says that this is a result of the Spring Transaction Manager. Unfortunately, for this particular method, I need to manually control the transaction.</p>
  
  <p>Relevant code is below:</p>
  
  <pre><code>// from generic non-abstract repository
  @Transactional
  public void saveList(List&lt;T&gt; objectList) {
      Session session = sessionFactory.getCurrentSession();
      Transaction tx = session.beginTransaction();
      int i = 1;
      for (T obj : objectList) {
  
          session.save(obj);
          //sessionFactory.getCurrentSession().save(obj);
          i++;
          if (i % 500 == 0) {
              session.flush();
              //sessionFactory.getCurrentSession().flush();
          }
      }
      if (!tx.wasCommitted()) {
          tx.commit();
      }
      //sessionFactory.getCurrentSession().getTransaction().commit();
  }
  </code></pre>
  
  <p>Configuration from applicationContext.xml:</p>
  
  <pre><code>&lt;tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/&gt;
      &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Any assistance is appreciated.</p>