Allow different AuditStrategy for each audited Entity

Description

Hello,

with the AuditStrategy became more flexible and extensible.
But the configuration, which implementation of AuditStrategy to use, is a global one. Wouldn't it be cool to use a custom AuditStrategy for one single audited Entity? Something like this:

@Audited(strategy = "com.company.CustomAuditStrategy")
@Entity
public class MyEntity {}

Each other audited Entity uses the standard configuration from org.hibernate.envers.audit_strategy

Regards, Rokko

Environment

None

Activity

Show:
Chris Cranford
November 26, 2018, 3:16 PM

This is a neat concept, my fear though is it is something that won't be used very much. In these situations, I often find it best to locate a middle ground where a feature behavior can be explored without impacting the core system.

With HHH-13051, I think we can do what you ask but with a single strategy. The configured AuditStrategy is only ever instantiated once during bootstrap, so its possible that the strategy can use reflection build some structures that the strategy can use to know how to handle certain entity mappings later on.

In short, treat the configured single AuditStrategy as a way to delegate to other strategies. In user code land, you could easily introduce custom annotation-markers that the global strategy inspects during bootstrap and when it finds a given annotation-marker, it adds an entry for that entity into a map to delegate to strategy X versus Y. This delegation would happen both for adding/extending tables but also for the perform operations.

I think the side effect is this proves whether or not a multi-strategy setup would work; particularly when associations are involved between entities.

What do you think?

Rokko11
November 26, 2018, 3:23 PM

Hello,
yes, you're right! This is an implementation detail which could be delegated by a custom audit strategy. I will do this as you suggest.

Regards, Rokko

Chris Cranford
November 27, 2018, 2:39 PM

I'm going to close this feature request but I would be interested in knowing your results with this experiment. Please update this issue with your findings for me and if you encounter a bug, don't hesitate to open a new issue and reference this one so we have context on the use case.

Assignee

Chris Cranford

Reporter

Rokko11

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor
Configure