I'm trying to map a session logout and I've implemented using events in a SEAM
way
<event type="org.jboss.seam.preDestroyContext.SESSION">
| <action expression="#{authenticator.logout}"/>
| </event>
|
and the code is
@Transactional
| public void logout() {
| if (identity.isLoggedIn()) {
| userLogin = entityManager.merge(userLogin);
| userLogin.setLogoutDate(new java.util.Date());
|
| entityManager.persist(userLogin);
|
| System.out.println("Logout: " + userLogin.getUser().getLogin());
| }
| }
The problem: The logout date is not recorded, i.e the entityManager.persist doesn't
take effect.
I also tryed an entityManager.flush(); after entityManager.persist(userLogin); but it
raises an exception
18:45:39,218 ERROR [[/mdrtb-moldova]] Session event listener threw exception
| javax.el.ELException: javax.persistence.TransactionRequiredException: no transaction
is in progress
| at com.sun.el.parser.AstValue.invoke(AstValue.java:155)
| at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
| at org.jboss.seam.util.UnifiedELMethodBinding.invoke(UnifiedELMethodBinding.java:36)
| at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:106)
| at org.jboss.seam.core.Events.raiseEvent(Events.java:63)
| at org.jboss.seam.contexts.Contexts.destroy(Contexts.java:214)
| at org.jboss.seam.contexts.Lifecycle.endSession(Lifecycle.java:287)
| at org.jboss.seam.servlet.SeamListener.sessionDestroyed(SeamListener.java:45)
| at org.apache.catalina.session.StandardSession.expire(StandardSession.java:687)
| at org.apache.catalina.session.StandardSession.isValid(StandardSession.java:579)
| at org.apache.catalina.session.ManagerBase.processExpires(ManagerBase.java:678)
| at org.apache.catalina.session.ManagerBase.backgroundProcess(ManagerBase.java:663)
| at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1284)
| at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1569)
| at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1578)
| at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1578)
| at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1558)
| at java.lang.Thread.run(Unknown Source)
| Caused by: javax.persistence.TransactionRequiredException: no transaction is in
progress
| at
org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:293)
| at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:81)
| at com.rmemoria.mdrtb.seam.AuthenticatorBean.logout(AuthenticatorBean.java:75)
| at
com.rmemoria.mdrtb.seam.AuthenticatorBean$$FastClassByCGLIB$$99838e3b.invoke(<generated>)
| at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
| at
org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:45)
| at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
| at
org.jboss.seam.interceptors.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:34)
| at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
| at
org.jboss.seam.interceptors.TransactionInterceptor$1.work(TransactionInterceptor.java:32)
| at org.jboss.seam.util.Work.workInTransaction(Work.java:37)
| at
org.jboss.seam.interceptors.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:27)
| at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
| at
org.jboss.seam.interceptors.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:47)
| at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
| at
org.jboss.seam.interceptors.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:27)
| at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
| at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
| at
org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:154)
| at
org.jboss.seam.intercept.JavaBeanInterceptor.intercept(JavaBeanInterceptor.java:89)
| at
com.rmemoria.mdrtb.seam.AuthenticatorBean$$EnhancerByCGLIB$$52b6f1c9.logout(<generated>)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
| at java.lang.reflect.Method.invoke(Unknown Source)
| at com.sun.el.parser.AstValue.invoke(AstValue.java:151)
| ... 17 more
I have no idea how to work around that. Any tip?
Ricardo
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4024766#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...