Hibernate envers:如何获取当前已审核表名?

问题描述 投票:0回答:1

使用Hibernate Envers,是否可以获得当前的审计表?我以《Hibernate Envers》为例,从 文档 但我增加了一列 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?

    }
}

我发现了这个旧帖子 从hibernate envers获取审计表名? 但没有相关答案。非常感谢

java hibernate hibernate-envers auditing spring-data-envers
1个回答
0
投票

你可以使用 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();
        }
© www.soinside.com 2019 - 2024. All rights reserved.