New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EntityType and ValueObjectType spawning/interring not working properly with Serializable interface (or other parent interfaces) #601
Comments
Interesting case. Thanks for providing the runnable test. I will take a look at this. |
I just found a workaround. Instead of letting Javers creating those Managed Type, I copied the Javers bean from the JaversMongoAutoConfiguration class and explicitly registered my Classes like so : @DependsOn("mongoTemplate")
@Bean
public Javers javers(MongoTemplate mongoTemplate, JaversProperties javersProperties) {
return JaversBuilder.javers()
.withListCompareAlgorithm(ListCompareAlgorithm.valueOf(javersProperties.getAlgorithm().toUpperCase()))
.withMappingStyle(MappingStyle.valueOf(javersProperties.getMappingStyle().toUpperCase()))
.withNewObjectsSnapshot(javersProperties.isNewObjectSnapshot())
.withPrettyPrint(javersProperties.isPrettyPrint())
.withTypeSafeValues(javersProperties.isTypeSafeValues())
.registerJaversRepository(new MongoRepository(mongoTemplate.getDb()))
.withPackagesToScan(javersProperties.getPackagesToScan())
.registerEntities(Role.class, Permission.class) // <-- added line
.build();
} I'll leave this open for you @bartoszwalacik if you want to dig a little deeper. |
It's a good workaround, you can register your types explicitly but type inferring should also work. I will check why it doesn't. |
fix released in 3.7.0 |
So I've encountered a weird bug (or feature?) in Javers. The method
ReflectionUtil.calculateHierarchyDistance()
calculates the distance to be used inTypeMapperState.findNearestAncestor()
. However, in the latter method there's this checkif(distances.get(0).isMax())
that will allow a null value to be returned by the method to be then used as anOptional.ofNullable(prototype)
in theTypeMapperState.infer
which will cause theprototype
to NOT be present in theTypeFactory.infer()
method which will then allow the javatype to be passed to inferFromAnnotations and eventually end up as anEntityType
and not aValueObjectType
.Here is my class hierarchy:
Here are the logs :
With Serializable interface on parent class
Without Serializable interface on parent class
When AbstractPermission doesn't implement Serializable both object are known as EntityType during.
When AbstractPermission implements Serializable, Role object will get
spawned as ValueObjectType from prototype ValueObjectType{baseType:interface java.io.Serializable}
and will get the following error when getting changesWill throw a :
It's a really complex problem and I'm pretty sure
ReflectionUtil.calculateHierarchyDistance()
isn't calculating something right...You can test my case with my repository https://github.com/philippeboyd/javers-issue-managed-type
The text was updated successfully, but these errors were encountered: