在Jhipster中使用Javers时出现此错误。我使用了Spring Boot的配置:
javers:
mappingStyle: FIELD
algorithm: SIMPLE
commitIdGenerator: synchronized_sequence
prettyPrint: true
typeSafeValues: false
newObjectSnapshot: false
packagesToScan:
auditableAspectEnabled: true
springDataAuditableRepositoryAspectEnabled: true
sqlSchema:
sqlSchemaManagementEnabled: true
sqlGlobalIdCacheDisabled: false
objectAccessHook: org.javers.hibernate.integration.HibernateUnproxyObjectAccessHook
prettyPrintDateFormats:
localDateTime: 'dd MMM yyyy, HH:mm:ss'
zonedDateTime: 'dd MMM yyyy, HH:mm:ssZ'
localDate: 'dd MMM yyyy'
localTime: 'HH:mm:ss'
public Object getIdOf(Object instance) {
Validate.argumentIsNotNull(instance);
if (!this.isInstance(instance)) {
throw new JaversException(JaversExceptionCode.NOT_INSTANCE_OF, new Object[]{this.getName(), this.getBaseJavaClass().getName(), instance.getClass().getName()});
} else if (this.hasCompositeId()) {
Map compositeId = Collections.unmodifiableMap((Map)this.idProperties.stream().filter((p) -> {
return p.get(instance) != null;
}).collect(Collectors.toMap((p) -> {
return p.getName();
}, (p) -> {
return p.get(instance);
})));
if (compositeId.isEmpty()) {
throw new JaversException(JaversExceptionCode.ENTITY_INSTANCE_WITH_NULL_COMPOSITE_ID, new Object[]{this.getName(), this.getIdPropertyNames()});
} else {
return Collections.unmodifiableMap(compositeId);
}
} else {
Object cdoId = this.getIdProperty().get(instance);
if (cdoId == null) {
throw new JaversException(JaversExceptionCode.ENTITY_INSTANCE_WITH_NULL_ID, new Object[]{this.getName(), this.getIdProperty().getName()});
} else {
return cdoId;
}
}
}
public boolean isInstance(Object cdo) {
Validate.argumentIsNotNull(cdo);
return this.baseJavaClass.isAssignableFrom(cdo.getClass());
}
当我尝试修改实体时,Javers引发了 JaversExceptionCode.NOT_INSTANCE_OF 异常。
错误消息是:
Can't create InstanceId for EntityType 'Objective', class 'com.project.domain.Objective' bounded to EntityType is not assignable from given class 'com.project.domain.Objective'
此错误仅在我停止/启动应用程序时发生。但这不是定期发生的。我不知道Javers中是否有任何缓存。我们需要在每次重新启动应用程序时清除此问题。
实际上,我无法提供隔离该错误的测试用例,因为它与项目的模型映射有关。它还需要创建Jhipster上下文来重现该错误。 然后让我在这里提出问题。我希望有人遇到类似的问题。