Provide a simple way to obtain a list of all audited entities.

Description

Currently, the method org.hibernate.envers.AuditReader.isEntityClassAudited can be used to check if an entity is audited.

It would be nice to have access to all audited entites through the AuditReader.

Environment

hibernate.version 5.2.10.Final

Activity

Show:
Jérémy Simar
October 4, 2017, 1:39 PM
Edited

Here's some workarounds

By java.lang.reflect:

By hibernate's Entity Manager:

Chris Cranford
October 5, 2017, 2:47 PM
Edited

Based on the workarounds you have shown, you illustrate that only the class-name for managed entity types that are audited suffices. But what your code does not illustrate is the purpose behind needing these values and that is what I am interested in having a better understanding for.

Are you trying to gain further details from EnversService by fetching an EntityConfiguration object?
Are you inspecting the actual EntityType's JPA metamodel?

Having a bit more depth as to why you need this can go a long way in making sure that we provide an adequate API for a user's needs that goes beyond simply just exposing some collection of Class<?> objects or String class-names.

Jérémy Simar
October 6, 2017, 6:20 AM

Hi,
First of all thank you for your response.

We are trying to get all audited class in order to present them to the user. With this list, the user can select one or more class to see all changes of all objets of this these class

Chris Cranford
October 6, 2017, 3:27 PM

I personally think there may be some value in exposing a run-time model that users can inspect. The only concern I have presently is that EntityConfiguration is mutable and I'd ideally prefer this run-time model that we expose to be immutable. There is a fair bit of internal changes that are planned throughout the 6.x release stream, so adding this as a part of that rework should be quite easy.

If I had to suggest either of your workarounds, it would be the one based on the JPA metamodel. It will remain portable across both major versions and adheres to a public API without accessing any internals of either ORM or Envers. I can tell you that the reflection approach using EnversServiceImpl will not be portable to 6.x at all.

Assignee

Unassigned

Reporter

Jérémy Simar

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Trivial
Configure