title: Hibernate transaction block issue
body: <p>Here is code from my relevant <strong>DAO</strong> class</p>
  
  <p>@Autowired
      private SessionFactory sessionFactory;</p>
  
  <pre><code>public void getTabletbyNameAndSave(String []selectedMedicines) {
      sessionFactory.getCurrentSession().beginTransaction();
      EPrescriber ePrescriber=new EPrescriber();
      List&lt;SelectedTablets&gt; selectedTabletsList=new ArrayList&lt;SelectedTablets&gt;();
      for (String item : selectedMedicines) {
  
          Tablets tablets=null;   
          String hql="from Tablets t where t.category='"+item.trim()+"' ";
          Query queryList = sessionFactory.getCurrentSession().createQuery(hql);
          tablets=(Tablets)queryList.uniqueResult();
  
          SelectedTablets selectedTablets=new SelectedTablets();
          selectedTablets.setTablets(tablets);
          selectedTablets.setePrescriberid(ePrescriber);
          selectedTabletsList.add(selectedTablets);
          sessionFactory.getCurrentSession().save(selectedTablets);
  
      }
  
      ePrescriber.setPatientName("Kasun");
      ePrescriber.setSelectedTablets(selectedTabletsList);
      sessionFactory.getCurrentSession().save(ePrescriber);
      sessionFactory.getCurrentSession().getTransaction().commit();       
  }
  </code></pre>
  
  <p>Here is my error. It seems that my transaction block is not handled correctly. Please help advise me on this problem. Thanks!</p>
  
  <pre><code>org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started
      at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:660)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
      at com.priyan.patients.EPrescriberDAO$$EnhancerByCGLIB$$3ce885f5.getTabletbyNameAndSave(&lt;generated&gt;)
      at com.priyan.patients.ContactsControllers.setTabletsNames(ContactsControllers.java:328)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
      at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
      at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
      at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
      at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1760)
      at java.lang.Thread.run(Unknown Source)
  Caused by: org.hibernate.TransactionException: Transaction not successfully started
      at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:131)
      at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
      ... 33 more
  </code></pre>