| Assuming EntityA and EntityB has a many-to-many relationship where EntityB defines the relation with mappedBy.
EntityA entityA = new EntityA();
EntityB entityB = new EntityB();
entityA.getMtmEntityBEntities().add(entityB);
If the entity that has the JoinTable annotation sets the relation, the audit table for the other entity will not have any values in any properties that are defined. The consequence for this is that when fetching the revision of EntityB like this when the relation was set, any properties will return null.
AuditReader reader = AuditReaderFactory.get(session);
List<Number> revisions = reader.getRevisions(EntityB.class, entityBId);
EntityB entityBRevision = reader.find(EntityB.class, entityBId, revisions.get(1)); entityBRevision.getData();
However, if we instead use EntityB to set the relation.
entityB.getMtmEntityAEntities().add(entityA);
... then the audit tables for EntityA and EntityB will be correct and contain all properties. I've attached a test case. |