2017-07-28 67 views
1

我的代碼有錯誤getTokenDAO().updateDate(newtok, new Date());線彈出org.hibernate.HibernateException: No Session found for current thread。請幫我解決這個問題。下面是我的編碼Java- TimerTask-org.hibernate.HibernateException:沒有找到當前線程的會話

Timer t = new Timer(); 
t.scheduleAtFixedRate(
    new TimerTask() { 
     public void run() { 
      try { 
       getTokenDAO().updateDate(newtok, new Date()); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
      System.out.println("5 minutes passed"); 
     } 
    }, 
    0,  // run first occurrence immediately 
    300000); 
} 

PS:我使用Spring

回答

0

調度程序將在一個新的線程運行TimerTask。會話/事務保存在一個ThreadLocal變量中。

您必須在您的TimerTaskrun()方法內部開一個新的交易。

相關問題