I think that having the relation from StateTransition to Event marked targetAuditMode= RelationTargetAuditMode.NOT_AUDITED and having the entity Event audited is a bit confusing...
Do you want to audit Event or not?
The semantic of the relationTargetAuditMode.NOT _AUDITED is that the related entity hasn`t history. There is not a hoctoric table and instead of that, envers resolve the relation to the entity through hibernate session.
I hope it will be helpful.
I realised this behaviour yesterday. In my case the Event and StateTransition objects are manipulated in different transactions, hence, they get different revision numbers. If I remove the relationTargetAuditMode.NOT _AUDITED annotation from the Event, then Evenrs would resolve the association from the Event historic table with the same revision number as the (historic) audited-StateTransition object. In other words, in this case getting the Event object from the historic StateTransition would always return null as the result of removing relationTargetAuditMode.NOT _AUDITED. Another option is NOT to audit the Event. But, the later means that I would lose the logs on creation and changes made to the Event objects.
So, how can I get around this issue?
Again, I don't quite understand why you would get a null there . I think you would get null only if the Event/StateTransition didn't exist at a given revision. Otherwise, you should get correct data.
Maybe you can create a small test case on what you are trying to achieve, so that it will be easier for both of us to understand what's going on?
looking at the code, Envers uses the annotation on an entity to determine whether to retrieve it from the historic-table or the table where the entity is stored. It be more correct to leave this decision to the annotation on the relation, then the expected data should correctly be retrieved.
Hmm I don't get the difference in the approaches you described