title: HibernateException: Could not obtain transaction-synchronized Session for current thread
body: <p>I am getting error:</p>
  
  <pre><code>Exception in thread "main" org.hibernate.HibernateException: 
  Could not obtain transaction-synchronized Session for current thread
  </code></pre>
  
  <p><strong>main</strong></p>
  
  <pre><code>ppService.deleteProductPart(cPartId, productId);
  </code></pre>
  
  <p><strong>@Service("productPartService")</strong></p>
  
  <pre><code>@Override
  public void deleteProductPart(int cPartId, int productId) {
      productPartDao.deleteProductPart(cPartId, productId);
  }
  </code></pre>
  
  <p><strong>@Repository("productPartDAO")</strong></p>
  
  <pre><code>@Override
      public void deleteProductPart(ProductPart productPart) {
          sessionFactory.getCurrentSession().delete(productPart);
      }
  
  
  @Override
      public void deleteProductPart(int cPartId, int productId) {
          ProductPart productPart  = (ProductPart) sessionFactory.getCurrentSession()
                  .createCriteria("ProductPart")
                  .add(Restrictions.eq("part", cPartId))
                  .add(Restrictions.eq("product", productId)).uniqueResult();
          deleteProductPart(productPart);
      }
  </code></pre>
  
  <p>How to fix it?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>If I modify method like this:</p>
  
  <pre><code>@Override
  @Transactional
  public void deleteProductPart(int cPartId, int productId) {          
      System.out.println(sessionFactory.getCurrentSession());
  }
  </code></pre>
  
  <p>It returns: </p>
  
  <pre><code>SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[] collectionQueuedOps=[] unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])
  </code></pre>
  
  <p>But if I remove <code>@Transactional</code> it ends up with exception:</p>
  
  <pre><code>org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
  </code></pre>
  
  <p>I get it working by adding <code>@Transactional</code>, but now I am getting <code>org.hibernate.MappingException: Unknown entity: ProductPart</code> although I chained <code>.uniqueResult()</code> to <code>Criteria</code>. How to fix it?</p>