2013-02-26 40 views
0

我正在使用Java,hibernate,SEAM和Richfaces。服務器JBOSS到期時更新數據庫

我在數據庫中保存了一個指示用戶登錄的寄存器,現在我需要在服務器會話過期的時候保存在數據庫中。 我實現了一個實現HttpSessionListener的類。我把方法sessionDestroyed一些像下一個:

  ... 
      historia.setFechafinal(new Date()); 
    historia.setGlosa("test"); 
    historia.setTiempo("tiempo"); 
    entityManager.persist(historia); 
      ... 

當我想堅持對象historia錯誤拋出。這應該是因爲會話已過期,組件entityManager不存在。

會話過期後,如何在數據庫中寫入數據?我是這個科目的新手。

謝謝你

回答

0

您可以使用一個觀察者對於這一點,每當HTTP會話被銷燬的方法將被解僱

@In User user; //User stored in session scope 

@Observer("org.jboss.seam.preDestroyContext.SESSION") 
public void userSessionDestroy(){ 

    //do something with User here 

} 
相關問題