服务器JBOSS会话到期时更新数据库

时间:2013-02-26 15:03:05

标签: jboss richfaces seam

我正在使用Java,hibernate,SEAM和Richfaces。

我在数据库中保存了一个注册表明用户正在登录,现在我需要在服务器会话到期时保存在数据库中。 我实现了一个实现HttpSessionListener的类。我在方法sessionDestroyed中添加了一些像下一个:

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

当我想要保留对象历史记录时,会抛出错误。这应该是因为组件entityManager因会话已过期而不存在。

会话过期后如何在数据库中写入?我是这个主题的新秀。

谢谢你

2 个答案:

答案 0 :(得分:1)

您可以尝试使用Seam的Run As功能。我们将它用于在没有登录用户的情况下在后台运行的某些预定进程。

http://docs.jboss.org/seam/2.2.2.Final/reference/en-US/html/security.html#d0e13810

答案 1 :(得分:0)

您可以使用观察者,每当http会话被销毁时都会触发该方法

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

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

    //do something with User here

}
相关问题