title: JPA. No transactional EntityManager available
body: <p>I'm use JPA (Hibernate 4 vendor) and Spring 3.2.x.
  I use this code for get Session and re-attach my detached entity.</p>
  
  <pre><code>Session session = entityManager.unwrap(Session.class);
  </code></pre>
  
  <p>My code look like this :</p>
  
  <pre><code>@Service
  public class SchedulerServiceImpl implements SchedulerService {
      @PersistenceContext
      private EntityManager entityManager;
  
      @Override
      @Transactional
      @Scheduled(fixedDelay = 5000)
      public void executeTasks() { 
         .. code ..
         while (tasksIterator.hasNext()) {
  
              SchedulerTask readyTask = recalculation(currentTask);
        }
        .. code ...
      }
  
     @Override
     @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
      public Deposit recalculation(SchedulerTask schedulerTask) {
           boolean asda = entityManager.isOpen(); // get TRUE
           Session session = entityManager.unwrap(Session.class); // Exception here
           session.update(schedulerTask);
           ... code ...
    }
  }
  </code></pre>
  
  <p>What's wrong? </p>
  
  <p>error :</p>
  
  <pre><code>   00:21:52,180 ERROR [org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler]
   (pool-10-thread-1) Unexpected error occurred in scheduled task.:
   java.lang.IllegalStateException: No transactional EntityManager
   available
          at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invokeSharedEntityManagerCreator.java:224)
   [spring-orm-3.2.4.RELEASE.jar:3.2.4.RELEASE]
          at com.sun.proxy.$Proxy36.unwrap(Unknown Source)
          at com.jar.dom.service.SchedulerServiceImpl.recalculation(SchedulerServiceImpl.java:133)
   [classes:]
          at com.jar.dom.service.SchedulerServiceImpl.executeTasks(SchedulerServiceImpl.java:92)
   [classes:]
  </code></pre>