Users often ask about a situation where they have 2 entities that are related with a one-to-one relationship and would like to have the ability to audit both sides of that relationship when the other side changes. The current approach explained to users who want this is to either: 1. Use conditional auditing 2. Use a special custom field on both entities. The problem with (1) is that it is very intrusive in 5.x and prior. It requires a great deal of code extension and overrides to just get it working and users need to be extremely careful with what they do in the listeners to not miss/create rows incorrectly. The problem with (2) is that its intrusive by nature to the domain model. It forces users to add a completely unnecessary field and add JPA callbacks or business hooks to manage that value when the correct conditions are present just to have a way to influence Envers. Perhaps the better solution would be to introduce an Envers specific annotation which allows users to explicitly identify to Envers these use cases and Envers would therefore audit those entity relationships? The care and concern here would be how to deal with situations of lazy-loading between them. |