Hibernate envers:如何获取当前审核的table名称?

Hibernate envers: how to get the current audited table name?

使用 Hibernate Envers,是否可以获取当前审核的 table?我从 doc 中获取了示例,但我添加了一个额外的列 tableName:

@Entity
@RevisionEntity(ExampleListener.class)
public class ExampleRevEntity extends DefaultRevisionEntity {
    private String username;
    private tableName;
    ...
}

听众:

public class ExampleListener implements RevisionListener {

    public void newRevision(Object revisionEntity) {
        ExampleRevEntity exampleRevEntity = (ExampleRevEntity) revisionEntity;
        ...
        exampleRevEntity.setUsername(...);

        exampleRevEntity.setTableName(...); // How to get the current table audited table?

    }
}

我找到了这个旧的 post Get audit table name from hibernate envers? 但没有相关答案。 非常感谢

您可以使用 EntityTrackingRevisionListener,它是 RevisionListener 的扩展。

    public class ExampleRevEntityListener
                 implements EntityTrackingRevisionListener {
        @Override
        public void entityChanged(java.lang.Class entityClass, java.lang.String entityName, 
           java.io.Serializable entityId, RevisionType revisionType, java.lang.Object revisionEntity) {

            Table tableAnnotation = entityClass..getAnnotation(javax.persistence.Table.class).name();
        }