|
I think the problem/reason is in org.hibernate.envers.entities.mapper.relation.lazy.ToOneDelegateSessionImplementor#doImmediateLoad
public Object doImmediateLoad(String entityName) throws HibernateException {
if(entCfg.getNotVersionEntityConfiguration(entityName) == null){
return versionsReader.find(entityClass, entityName, entityId, revision);
} else {
return delegate.immediateLoad(entityName, (Serializable) entityId);
}
}
The versionsReader.find(...) is used always to return result immediatly if entityName is configured as @Audited, doesn't matter if it is only asking reference for property annotated as targetAuditMode=RelationTargetAuditMode.NOT_AUDITED (Employee.company from example in description)
What about to slightly change ToOneDelegateSessionImplementor#doImmediateLoad and add fallback to delegate if versionsReader.find(entityClass, entityName, entityId, revision) == null ?
public Object doImmediateLoad(String entityName) throws HibernateException {
Object immediatlyLoaded = null;
if (entCfg.getNotVersionEntityConfiguration(entityName) == null) {
immediatlyLoaded = versionsReader.find(entityClass, entityName, entityId, revision);
}
if (immediatlyLoaded == null) {
return delegate.immediateLoad(entityName, (Serializable) entityId);
}
}
It doesn't solve problem mentioned in description with 'purging feature' but solves the real case when we started with @Audited Employee but not-audited Company and after some period made Company @Audited
So it is easier than what proposed in description
1. Look up related entity with the max revision number equal or less than the targeted entity's revision number. 2. If not found, look up related entity with the min revision number larger than the targeted entity's revision number. 3. If not found, look up related entity in "current" version. 4. If not found, return null or empty entity with id field populated.
and just 1. Look up related entity with the max revision number equal or less than the targeted entity's revision number. // versionsReader.find(entityClass, entityName, entityId, revision); 2. If not found, look up related entity in "current" version in real table // delegate.immediateLoad(entityName, (Serializable) entityId);
Otherwise we have to create initial revisions for Company in scope of migration effort Is there some generic tool to do this ? I found
|