如何在没有Seam的情况下访问Hibernate Envers中的FacesContext? [英] How to access FacesContext in Hibernate Envers without Seam?

查看:86
本文介绍了如何在没有Seam的情况下访问Hibernate Envers中的FacesContext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在我们的数据库审计项目中实施Envers,并陷入困境。我们不知道如何确定用户正在进行更改。我可以找到的所有示例都使用Seam和它们的Component.getInstance技术。
$ b $ ul
  • Glassfish 3.1.2.2
  • Mojarra 2.1.13

  • Hibernate 4.1.6.Final



  • 这是我们的自定义修订版实体

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

    私人字符串登录;

    getters / setters ...
    }

    自定义修订监听器

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

    //我们如何获得FacesContext /远程用户?

    rev.setLogin(unknown);


    我们已经尝试了注入和范围确定无济于事,我们也尝试了这个 ClassLoader解决方案,但是getCurrentInstance()仍然为null;

    感谢您的帮助!

    解决方案

    adamw是正确的,FacesContext.getCurrentInstance()在定制的RevisionListener中工作。



    我们有一个javax.servlet.Filter实现试图处理doFilter()方法中的事务,该方法由于任何原因导致FacesContext.getCurrentInstance()返回null RevisionListener。我们昨天从web.xml中删除了它,原因不同,当我今天早上尝试getCurrentInstance()时没有它,一切正常。



    感谢大家的回复,也许这有助于别人。


    We're implementing Envers in our project for database auditing, and have run into a snag. 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.

    • Glassfish 3.1.2.2
    • Mojarra 2.1.13
    • Hibernate 4.1.6.Final

    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;

    Thanks for your help!

    解决方案

    adamw was correct, FacesContext.getCurrentInstance() does work in a custom 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. We removed that from the web.xml yesterday for a different reason and when I tried getCurrentInstance() without it this morning, everything works fine.

    Thanks for the replies everyone, maybe this will help someone else someday.

    这篇关于如何在没有Seam的情况下访问Hibernate Envers中的FacesContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆