简体   繁体   English

如何在没有接缝的Hibernate Envers中访问FacesContext?

[英]How to access FacesContext in Hibernate Envers without Seam?

We're implementing Envers in our project for database auditing, and have run into a snag. 我们正在项目中实施Envers进行数据库审核,但遇到了麻烦。 We don't know how to determine what user is making the change. 我们不知道如何确定进行更改的用户。 All the examples I can find use Seam and their Component.getInstance technique. 我可以找到的所有示例都使用Seam及其Component.getInstance技术。

  • Glassfish 3.1.2.2 玻璃鱼3.1.2.2
  • Mojarra 2.1.13 Mojarra 2.1.13
  • Hibernate 4.1.6.Final Hibernate 4.1.6。最终版

Here's our custom Revision Entity 这是我们的自定义修订实体

@Entity
@RevisionEntity(CustomRevisionListener.class)
public class CustomRevisionEntity {
    @Id
    @GeneratedValue
    @RevisionNumber
    private int id;

    private String login;

    getters/setters...
}

And out custom Revision Listener 并自定义修订监听器

public class CustomRevisionListener implements RevisionListener {
    @Override
    public void newRevision(Object revisionEntity) {
        CustomRevisionEntity rev = (CustomRevisionEntity) revisionEntity;

        //how do we get the FacesContext/remote user?

        rev.setLogin("unknown");
    }
}

We've tried injection and scoping to no avail, we also attempted this ClassLoader solution I found for something that seemed to be a similar circumstance, but getCurrentInstance() was still null; 我们尝试了注入和作用域,但都没有成功,我们还尝试了我发现的ClassLoader解决方案 ,该解决方案似乎是类似的情况,但是getCurrentInstance()仍然为null。

Thanks for your help! 谢谢你的帮助!

adamw was correct, FacesContext.getCurrentInstance() does work in a custom RevisionListener. adamw是正确的,FacesContext.getCurrentInstance()确实可以在自定义的RevisionListener中工作。

We had a javax.servlet.Filter implementation attempting to handle the transaction in the doFilter() method which was for whatever reason causing FacesContext.getCurrentInstance() to return null in the RevisionListener. 我们有一个javax.servlet.Filter实现,尝试实现doFilter()方法中的事务,这是由于任何原因导致FacesContext.getCurrentInstance()在RevisionListener中返回null。 We removed that from the web.xml yesterday for a different reason and when I tried getCurrentInstance() without it this morning, everything works fine. 昨天,出于不同的原因,我们从web.xml中删除了该文件,当我今天早晨尝试不使用getCurrentInstance()时,一切正常。

Thanks for the replies everyone, maybe this will help someone else someday. 感谢大家的答复,也许有一天会有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM