You can audit the relation from Person to Name whitout auditing Name entity marking that relation as @Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED).
- The history instances of Person are going to reference the current instance of Name.
- If the relation changes, the related Name changes, but there is not historic instance of Name.
- If you delete a Name and it's referenced by an historic instance, it will fail.
Hope it will help.
Is there any way in which I can audit the actual foreign keys that existed when the history entries were created? I mean, can I have any history instance of Person reference the instance of Name that existed at the moment of its creation?
Having all the Person histories reference the current instance of name is of no use to me.
This is how I would like the Person and Person_AUD tables to look like.
Person: Id=3, Name_Id=234
Person_AUD: Id=3, REV=1, REVTYPE=0, Name_Id=234
After (changing the name):
Person: Id=3, Name_Id=345
Person_AUD:Id=3, REV=1, REVTYPE=0, Name_Id=234
Id=3, REV=2, REVTYPE=1, Name_Id=345
That's what you will have if you use @Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED).
This will work as expected as long as the Name entity is immutable (that is, a name never changes, but a reference from a Person to a Name can change).