capturing session information after a session ends
gebuh Aug 25, 2010 1:15 PMI'm trying to capture a user's start and end of a session and enter a timestamp and status in the database. I'm using an application scoped component that implements HttpSessionBindingListener and is created from a session scoped component. I can capture the start of the session, but not the end. It appears that when the session ends the entityManager no longer holds the component and generates a EntityManager is closed message or a context error if I use @Observer or LifeCycle. Is there any way to use the entityManager to do this?
this is where the code is blowing up:
@Name("userStatsSession") @Scope(ScopeType.APPLICATION) public class UserStatsSession implements Serializable, HttpSessionBindingListener { ... public void valueUnbound(HttpSessionBindingEvent event) { System.out.println("in userStatsSession.valueUnbound, not in if statement"); if(this.userstats.getUserId() != null){ System.out.println("in userStatsSession.valueUnbound, entityManager is " + this.entityManager); userMon.stop(); sessionMon.stop(); this.userstats.setLoggedOn(new BigDecimal(0)); UserStats chkStats = this.entityManager.merge(this.userstats);// code go BOOM!!! this.entityManager.flush(); System.out.println("userStatsSession.valueUnbound"); chkStats.printStats(); } } ... }
Error generated:
13:11:50,622 INFO [STDOUT] in userStatsSession.valueUnbound, entityManager is org.jboss.seam.persistence.EntityManagerProxy@841307 13:11:50,638 WARN [ContainerBase] Exception processing manager org.apache.catalina.session.StandardManager@c3ff07 background process java.lang.IllegalStateException: EntityManager is closed at org.hibernate.ejb.EntityManagerImpl.getSession(EntityManagerImpl.java:66) at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:235) at org.jboss.seam.persistence.EntityManagerProxy.merge(EntityManagerProxy.java:132) at com.raytheon.AtcotsEmployee.criteria.UserStatsSession.valueUnbound(UserStatsSession.java:153) at org.apache.catalina.session.StandardSession.removeAttributeInternal(StandardSession.java:1649) at org.apache.catalina.session.StandardSession.expire(StandardSession.java:756) at org.apache.catalina.session.StandardSession.isValid(StandardSession.java:592) at org.apache.catalina.session.ManagerBase.processExpires(ManagerBase.java:682) at org.apache.catalina.session.ManagerBase.backgroundProcess(ManagerBase.java:667) at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1327) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1612) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1621) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1621) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1601) at java.lang.Thread.run(Thread.java:619)
I'm using Seam 2.20 with jboss 5.1