title: spring hibernate transaction could not commit
body: <p>I wrote dao in spring as i used to write in struts some think like this</p>
  
  <pre><code>@Autowired
      private SessionFactory sessionFactory;
      Session session=null;
      Transaction tx=null;
     List&lt;Login&gt; users= null;
      try{
          session=sessionFactory.getCurrentSession();
          tx=session.beginTransaction();
          users=session.createQuery("from Login").list();
          tx.commit();
      }catch(Exception e){System.out.println("commit exception:"+e);
          try {tx.rollback();} catch (Exception ex) {System.out.println("rollback exception:"+ex);} 
      }finally{if(session!=null &amp;&amp; session.isOpen()){session.close();}}
  </code></pre>
  
  <p>but i am getting this <strong>error:</strong></p>
  
  <blockquote>
    <p>threw exception [Request processing failed; nested exception is
    org.springframework.transaction.TransactionSystemException: Could not
    commit Hibernate transaction; nested exception is
    org.hibernate.TransactionException: Transaction not successfully
    started] with root cause org.hibernate.TransactionException:
    Transaction not successfully started</p>
  </blockquote>
  
  <p>can someone please help me out.</p>
  
  <p>if i am writing it like this, </p>
  
  <pre><code>try{
              users=sessionFactory.getCurrentSession().createQuery("from Login").list();
          }catch(Exception e){System.out.println("commit exception:"+e);
  </code></pre>
  
  <p>its working fine, but is it safe?.</p>
  
  <p>Thanks and regards</p>