从休眠envers获取审计表名称? [英] Get audit table name from hibernate envers?

查看:98
本文介绍了从休眠envers获取审计表名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从Hibernate envers请求实体的审计表名称?我并不是说要获取实体的Hibernate表名并附加审计后缀的解决方案。

Is it possible to request the name of an audit table for a entity from Hibernate envers? I don't mean the solution of getting Hibernate table name for entity and appending the auditing postfix.

推荐答案

在Hibernate Envers 5中。 x,没有集中的方法来获取此信息,因此您必须查阅多个API才能获取此元数据。但是有 HHH-12014 HHH-12044 强调需要公开此内容,以便用户代码更容易使用。

In Hibernate Envers 5.x, there is no centralized way to obtain this information so you'll have to consult several APIs to get this metadata. But there is HHH-12014 and HHH-12044 that highlight the need to expose this so that it can be consumed by user code easier.

为了获取此信息,我们需要首先获取一些SPI,这些SPI仅可通过 SessionImplementor 接口使用。

In order to gain access to this information, we'll need to first obtain some SPIs that are only available via the SessionImplementor interface.

我必须强调,这种方法可以随每个发行版而改变,因为其中一些使用内部类和方法,这些类和方法不受跨次要版本和错误修正版本的兼容性限制

SessionImplementor si = entityManager.unwrap( SessionImplementor.class );



使用本地休眠状态



Using Native Hibernate

SessionImplementor si = (SessionImplementor) session;

一旦您拥有 SessionImplementor ,我们需要访问一些内部对象:

Once you have the SessionImplementor, we need to access some internal objects:

// Get the envers service, this is the central "holder" for envers in 5.x
EnversService enversService = si.getSessionFactory()
    .getServiceRegistry()
    .getService( EnversService.class );

// Next we get the audit entity configuration and get the audited entity name
AuditEntitiesConfiguration aec = enversService.getAuditEntitiesConfiguration();
String auditEntityName = aec.getAuditEntityName( yourEntityName );

// Now we need to get the entity information from ORM
EntityPersister persister = si.getSessionFactory().getEntityPersister( auditEntityName )
String tableName = ( (Queryable) persister ).getTableName();

这篇关于从休眠envers获取审计表名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆