how to get previouseState without fetching from the db using hibernate interceptor to create audit trail table?

后端 未结 1 468
面向向阳花
面向向阳花 2020-12-10 23:24

I am trying to create an Audit table that will ends looking something like that :

entity,id,property,oldValue,newValue,user,timestamp

相关标签:
1条回答
  • 2020-12-10 23:45

    An alternative approach is to store the previous state on load.

    @Entity
    @Table(name='Foo')
    class Foo {
    
        @Transient
        private Foo previousState;
    
        @PostLoad
        private void setPreviousState(){
            previousState = new Foo();
            //copy the fields
        }
    
        public Foo getPreviousState(){
            return previousState;
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题