6

Is it possible to add additional column in audit table?? For example i have a table like this

@Entity
@Table(name="EmpEnverPrac")
@Audited
public class EmpEnverPractice {


        @Id
        @Column(name="ID") 
        @GeneratedValue(strategy  = GenerationType.AUTO)
        private Integer id; 

        @Column(name="NAME") 
        private String name; 

        @Column(name="password")
        @NotAudited
        private String password; 

     // getter and setters

}

now i want some additional column in my generated audit table but i don't want to include them in my entity. I am not able to find any solution for this requirement. kindly tell me the required configuration. thanks in advance

rishi
  • 1,792
  • 5
  • 31
  • 63

2 Answers2

3

I found a workaround for my requirement because i can add additional column in REVINFO table(default name given by hibernate). This table stores id with timestamp for every transaction in application so i can get the information about any transaction. Reference is available here http://docs.jboss.org/envers/docs/#revisionlog

rishi
  • 1,792
  • 5
  • 31
  • 63
  • This will create a new rev table and there is no way to find out which transaction an ID in this rev table belongs to. Is there a way to find out? – Maz Dec 15 '17 at 05:08
0

Technically, this is strange requirement, review your business and design, if you need a base class and an extended class for the conception: EmpEnverPractice, if yes, you can map all fields on sub-class, and use base class without those fields you don't need.

Laurence Geng
  • 424
  • 3
  • 9
  • 1
    @Luurence i know this is strange requirement but it is our business requirement and i am not able to find any documentation for this. – rishi Aug 20 '14 at 12:44
  • 2
    @Laurence what about persisting id of currently logged in user who made a change to audited entity, I think this use case is very common and doesn't look strange. – troy Nov 16 '17 at 09:43
  • 2
    This isn't a strange requirement at all. – Chris Pfohl Mar 05 '18 at 21:09
  • Not a strange requirement. For example, distributed traces might need to be logged which do not make sense in the entity. – isopropylcyanide Feb 20 '21 at 18:48