You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicclassAnnotationRevisionMetadata<NextendsNumber & Comparable<N>> implementsRevisionMetadata<N> {
privatefinalLazy<Optional<N>> revisionNumber;
publicAnnotationRevisionMetadata(Objectentity, Class<? extendsAnnotation> revisionNumberAnnotation,
Class<? extendsAnnotation> revisionTimeStampAnnotation, RevisionTyperevisionType) {
Assert.notNull(entity, "Entity must not be null!");
Assert.notNull(revisionNumberAnnotation, "Revision number annotation must not be null!");
Assert.notNull(revisionTimeStampAnnotation, "Revision time stamp annotation must not be null!");
Assert.notNull(revisionType, "Revision Type must not be null!");
this.entity = entity;
this.revisionNumber = detectAnnotation(entity, revisionNumberAnnotation);
this.revisionDate = detectAnnotation(entity, revisionTimeStampAnnotation);
this.revisionType = revisionType;
}
publicOptional<N> getRevisionNumber() {
returnrevisionNumber.get();
}
privatestatic <T> Lazy<Optional<T>> detectAnnotation(Objectentity, Class<? extendsAnnotation> annotationType) {
returnLazy.of(() -> {
AnnotationDetectionFieldCallbackcallback = newAnnotationDetectionFieldCallback(annotationType);
ReflectionUtils.doWithFields(entity.getClass(), callback);
returnOptional.ofNullable(callback.getValue(entity));
});
}
}
AnnotationDetectionFieldCallback
publicclassAnnotationDetectionFieldCallbackimplementsFieldCallback {
public <T> TgetValue(Objectsource) {
Assert.notNull(source, "Source object must not be null!");
Fieldfield = this.field;
if (field == null) {
returnnull;
}
return (T) ReflectionUtils.getField(field, source);
}
}
DefaultRevisionMetadata calls Optional.of(entity.getId());
-> entity is HibernateProxy
-> HibernateProxy.getId();
AnnotationRevisionMetadata calls revisionNumber.get();
-> Optional.ofNullable(callback.getValue(entity))
-> ReflectionUtils.getField(field, source), @RevisionNumber annotated field value
Therefore, when using Custom RevisionEntity, the field value of the HibernateProxy
in org.springframework.data.history.Revision is null. Information about metadata is output only as null or Optional.empty.
if in custom RevisionEntity Adding @Proxy(lazy = false) causes n+1 issues similar issue
any way to solve this problem?
The text was updated successfully, but these errors were encountered:
The problematic code is in commons. We'd need either a way to configure the ways these values get accessed or switch to field access. But since the code is in commons we need to evaluate how that might affect other modules.
I have a problem when using custom entities, in spring data envers 2.5.3
When Create a new DefaultRevisionMetadata or AnnotationRevisionMetadata, metadata is HibernateProxy
EnversRevisionRepositoryImpl
DefaultRevisionMetadata
AnnotationRevisionMetadata
AnnotationDetectionFieldCallback
DefaultRevisionMetadata calls Optional.of(entity.getId());
-> entity is HibernateProxy
-> HibernateProxy.getId();
AnnotationRevisionMetadata calls revisionNumber.get();
-> Optional.ofNullable(callback.getValue(entity))
-> ReflectionUtils.getField(field, source), @RevisionNumber annotated field value
Therefore, when using Custom RevisionEntity, the field value of the HibernateProxy
in org.springframework.data.history.Revision is null. Information about metadata is output only as null or Optional.empty.
if in custom RevisionEntity Adding
@Proxy(lazy = false)
causes n+1 issues similar issueany way to solve this problem?
The text was updated successfully, but these errors were encountered: