我通过制作自己的访问挂钩解决了这个问题,并将其添加到 Javers 中
.withObjectAccessHook(新 EntityAccessHook()).build()
public class EntityAccessHook<T> extends HibernateUnproxyObjectAccessHook<T> {
@Override
public Optional<ObjectAccessProxy<T>> createAccessor(T entity) {
Optional<ObjectAccessProxy<T>> accessProxy = super.createAccessor(entity);
if (accessProxy.isEmpty() && entity instanceof AbstractUuidEntity) {
return fromEntityInitializer((AbstractUuidEntity) entity);
}
return accessProxy;
}
private Optional<ObjectAccessProxy<T>> fromEntityInitializer(
AbstractUuidEntity abstractUuidEntity) {
return Optional.of(
new ObjectAccessProxy(
() -> abstractUuidEntity,
abstractUuidEntity.getClass(),
abstractUuidEntity.getId() == null ? UUID.randomUUID() : abstractUuidEntity.getId()));
}
}