2 Replies Latest reply: Apr 13, 2012 9:46 AM by Sandro Queiroz Jr RSS

Hibernate Envers not working

Sandro Queiroz Jr Newbie

Hi guys,

 

I'm trying to add auditing functionality in a Struts 2 web project. I'm using Hibernate Envers for auditing. But it's not working. I can't get the user's session.

My code is:

 

package tarefas.auditoria;

 

import java.util.Map;

 

import org.hibernate.envers.RevisionListener;

 

import tarefas.modelo.Usuario;

 

import com.opensymphony.xwork2.ActionContext;

 

public class AuditoriaListener implements RevisionListener {

 

    @Override

    public void newRevision(Object arg0) {

        AuditoriaRevEntity auditoriaRevEntity = (AuditoriaRevEntity) arg0;

 

        Map<String, Object> sessao = ActionContext.getContext().getSession();

        Usuario usuarioLogado = (Usuario) sessao.get("usuarioLogado");

        auditoriaRevEntity.setLogin(usuarioLogado.getLogin());

    }

}

 

The line 17 is throwing an exception:

 

Map<String, Object> sessao = ActionContext.getContext().getSession();

 

The console:

 

11:52:06 ERROR [AssertionFailure] an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)

java.lang.NullPointerException

    at tarefas.auditoria.AuditoriaListener.newRevision(AuditoriaListener.java:17)

    at org.hibernate.envers.revisioninfo.DefaultRevisionInfoGenerator.generate(DefaultRevisionInfoGenerator.java:95)

    at org.hibernate.envers.synchronization.AuditProcess.getCurrentRevisionData(AuditProcess.java:124)

    at org.hibernate.envers.synchronization.AuditProcess.executeInSession(AuditProcess.java:106)

    at org.hibernate.envers.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:155)

    at org.hibernate.engine.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:554)

    at org.hibernate.engine.ActionQueue.beforeTransactionCompletion(ActionQueue.java:216)

    at org.hibernate.impl.SessionImpl.beforeTransactionCompletion(SessionImpl.java:571)

    at org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(JDBCContext.java:250)

    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:138)

    at tarefas.persistence.hibernate.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:40)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)

    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)

    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)

    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)

    at java.lang.Thread.run(Thread.java:662)

 

I'm using Open Session in View pattern to get hibernate's session: [url=https://community.jboss.org/wiki/OpenSessionInView]Open Session in View[/url]

Frameworks: Struts 2.3.1.2, Hibernate 3.6.10.Final

Container: Tomcat 6.0.24.

 

Ideas?