java.lang.InstantiationError after upgrading to Spring Boot 2.4.4 (spring data commons 2.4.6)
See original GitHub issueIn a Spring Boot application we use Spring Data Mongo to map some documents. Some of them have embedded documents with a hierarchy, e.g.:
@Document("projects")
@TypeAlias("project")
data class Project(
...
val budget: ProjectBudget)
abstract class ProjectBudget {
abstract fun getCurrentBudget(): MonetaryAmount?
}
@TypeAlias("projectProjectBudget")
class ClosedProjectBudget(... ) : ProjectBudget() {}
Up to Spring Boot 2.4.3 when retrieving a Project instance the corresponding ProjectBudget subclass what built correctly. However after the upgrade to Boot 2.4.4 we get this exception:
Caused by: java.lang.InstantiationError: xxx.ProjectBudget
at xxx.ProjectBudget_Instantiator_srp3na.newInstance(Unknown Source)
at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator$EntityInstantiatorAdapter.createInstance(ClassGeneratingEntityInstantiator.java:238)
at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:87)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:344)
There seems to be a regression when instantiating subclasses.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Spring Boot 2.4.4 failed to start after upgrading - Stack Overflow
I am upgrading Spring boot application, which is currently working on 2.1.13 to 2.4.4. After upgrade, spring boot application is not ...
Read more >Spring Data Commons - Reference Documentation
Dependency Management with Spring Boot. Spring Boot selects a recent version of Spring Data modules for you. If you still want to upgrade...
Read more >org.springframework.data:spring-data-commons vulnerabilities
version published direct vulnerabilities
3.0.0 18 Nov, 2022 0. C. 0. H. 0. M. 0. L
2.7.6 18 Nov, 2022 0. C. 0. H. 0....
Read more >org.springframework.data » spring-data-commons » 2.4.6
Compile Dependencies (32) ; Func. Programming Apache 2.0, logo, io.vavr » vavr (optional) ; Java Spec CDDLGPL 2.0, logo, javax.annotation » javax.
Read more >Spring Data Core 3.0.0 API - Javadoc.io
Core annotations being used by Spring Data. ... Support for registering the need for reflection, resources, java serialization and proxies at runtime for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This looks actually as if the subclass isn’t registered with MappingContext. To properly resolve the target class using TypeAlias, it must be already present in the context.
Can you isolate the issue and provide a minimal reproducer?
I entirely missed the fact of the custom Mongo configuration
MongoDbClientConfiguration
hence I relied on Spring Boot to perform the entity scan.I moved the ticket into Spring Data MongoDB. The difference comes from #3592 where we removed
@Persistent
as marker annotation from the entity scan in Spring Data MongoDB. Previously, this arrangement worked because@TypeAlias
is meta-annotated with@Persistent
and so entities annotated with@TypeAlias
are picked up as entities during the scan.ServiceProjectBudget
andProjectProjectBudget
aren’t subtypes ofProject
hence the@Document
annotation doesn’t apply these types. So annotating both types with@Document
is the way to go and it worked previously rather by accident and not by intent.