How to add some costom columns and set custom values in Audit table while saved AuditedEntity?

34 Views Asked by At

I used spring data envers in the project and added the @Audited annotation to the entity class to audit all fields.

Now, I want to extend some fields in the audit table to store additional information. For example, the UserInfo table has a roleId field. I want to add roleName to the corresponding audit table to save the roleName snapshot information associated with the roleId at that time, so that it can be easily displayed in the UserInfo change history page.

@Audited
@Entity
@Table(name = "user_info")
@Data
@DynamicInsert
@DynamicUpdate
public class UserInfo extends BaseEntity {

    @Id
    @Column(name = "id")
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "org.hibernate.id.UUIDGenerator")
    private String id;
    
    @Column(name = "name", length = 200)
    private String name;
    
    @Column(name = "role_id", length = 200)
    private String roleId;

} 

I expect that the **user_info_aud ** table can add a role_name field so that the role name snapshot can be displayed on the UserInfo change history page.

0

There are 0 best solutions below