| Well, honestly what you're after is already available to you through ORM. The key here is accessing it from within the bounded context of audited entities. I think ultimately this may somewhat correlate with
HHH-12014 Open . The core issue here is having a good way to reverse lookup an ORM entity to an Audited entity and then from there acquire the EntityPersister responsible for managing the audited entity table. There you can obtain all database related metadata including columns, table names, etc. As a very simple workaround:
EntityManager entityManager = SessionImplementor session = entityManager.unwrap( SessionImplementor.class );
AuditReader auditReader = AuditReaderFactory.get( entityManager );
EnversService enversService = session.getSessionFactory().getServiceRegistry().getService( EnversService.class );
for ( EntityType<?> entityType : entityManager.getMetamodel().entities() ) {
if ( entity.getJavaType() != null ) {
if ( auditReader.isEntityClassAudited( entityType.getJavaType() ) ) {
final String auditEntityName = enversService.getAuditedEntitiesConfiguration()
.getAuditedEntityName( entityType.getJavaType().getName() );
final EntityPersister entityPersister = session.getSessionFactory().getEntityPersister( auditEntityName );
}
}
}
Given what we're doing in 6.x, I'm inclined to suggest the above for any 5.x implementation for now and we'll look at improving upon this with 6.x since we'd be introducing new APIs. But I believe whatever we do introduce, it does align closely with
HHH-12014 Open either way. |