-
Notifications
You must be signed in to change notification settings - Fork 192
MappingInstantiationException
for Abstract Classes using tasks ran on ForkJoinPool
#1691
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
Comments
I moved the ticket into Spring Data Couchbase. The converter should honor the concrete type for properties holding values that do not exactly match the property type. I.e. for a When you mention that the application only fails after a certain time, this might indicate that the functionality isn't used right from the start or that a cache is being evicted. I'd ask you to verify whether the affected documents contain proper type hints. Since you're not using |
Hey there @mp911de .......thx for your comment! Here's what a sample of the document looks like when I pull a sample doc from Couchbase analytics. I am guessing the spring-data / Couchbase framework has been adding the "_class" attribute when saving to Couchbase all along. This must be how the reads work to understand what type of object to de-serialize. There were no special annotations done to make this work. We have done this in other API models outside of Couchbase using Jackson annotations such as @JsonTypeInfo and @JsonSubTypes. We never had to do this for the Couchbase entity model it just worked. Thoughts?
|
@cabbonizio - I'll investigate your issue. |
@mikereiche just to be clear you want an update to use spring-data-couchbase 4.4.9 ? |
Thank you so much for jumping in. A few other co-workers may also help contribute and answer questions. It sounds like we can force bump Spring Data Couchbase to 4.4.9 and we'll be like for like. I made a mistake we are actually on the following currently:
We can force bump spring data couchbase to 4.4.9 and then we're on same versions. |
And please let us know if there's anything else to check or try out |
I created an application from Spring Initialzr 2.7.9 (It doesn't let you pick the spring data version, it uses 4.4.8).
|
|
4.4.8 is fine. Can you show me the call that is attempting to retrieve the payment method? The definition (in the repository interface if that's how it's being called) and the actual call? |
There's an overall @document entity it's part of so it's retrieving the parent doc.....the payment methods are simply a list of embedded object....here's what the doc looks like:
I took out a lot of the attributes to keep it simple since there are a lot more. Repo looks like this:
In code we're using the CartRepository.findById() method...... |
I can't reproduce the problem. I add this Cart class :
And this CartRepository :
And use this driver class:
I get:
And the document looks like:
|
@ammw @BillTurnbull @cabbonizio |
If you set a break-point at line 231 in MappingCouchbaseConverter - you should see that resulting in
|
Thank you @mikereiche for all of your feedback so far. For us we can't reproduce local also only when it's deployed after some time which makes us wonder if this is self-inflicted based on a specific use-case where we maybe fail to convert the abstract to a concrete object of sorts. We're going to do some more testing and report back to this issue. Part of this is ruling out if there's any issue with the Spring components between data and Couchbase modules no evidence of that yet |
If the concrete class (the _class=class) doesn't extend the abstract class (maybe the class definition has changed), this can happen. If the _class=class is "not more concrete" than the abstract class, then it will use the abstract class. Another possibility is that a custom type mapper is configured, or that there is an @typealias configured. |
We are looking to add some Lombok equals and hash code annotations to all of the concrete classes since something seems off about the mapping instantiators. Our Developer found they are stored as follows.......... {class-name}+"instantiator"+{hashCode} Will report back with latest tests |
The error message "Failed to instantiate com.qvc.common.couchbase.model.cart.payment.AbstractPaymentMethod" indicates that DefaultTypeMapper.readType() could not determine the concrete type (documentsTargetType) based on the 'source' and was therefore trying to use the abstract type (basicType) which was used to define the repository. The issue looks more like an issue determining what the documentsTargetType is (or determining that it isMoreConcreteCustomType than the abstract type). Which points to the (sub)document not having a _class property, or the code not finding it because it is using a different @typealias than _class, or a custom TypeMapper (instead of the DefaultTypeMapper). (Or the aforementioned bug of not projecting _class, but that should be fixed in 4.4.8). The error message indicates it is trying to instantiate the wrong class - not any issue with instantiation of the correct class.
|
@mikereiche I think we have a breakthru and I'm going to let the team member who made the discovery comment on this thread soon. Many thanks for your patience. We kind of want to comment the finding on here to save others some future pain. If all remains good as it has no issues found with Spring Data Couchbase. We'll report back soon |
I would like to hear what you found. Closing show it doesn't show up in my open-issues list. |
@mikereiche What we found is that the particular service having the issue creates a CompletableFuture.runAsync(..) task to be run at the end of processing. That task retrieves all other cart documents belong to a user and scrubs them of data. The retrieval also uses spring-data-couchbase but does use a n1ql query rather than a key lookup to get the other carts. When testing local I found that some of the errors were originating from that async tasks reads from couchbase rather than the read of the cart document the was part of the service request. Suspecting a threading issue I changed that async task to be just a sync method call and we could no longer reproduce the issue. It turns out that the completable future was not specifying an Executor so was using the default forkjoinpool. I then changed to use the spring created Executor bean as an executor and could also no longer reproduce the issue. The root cause is not yet clear to me but it is definitely related to volume and perhaps the limited number of threads with forkjoinpool or the way forkjoinpool distributes work. So, changed:
to:
Any thoughts you have would be appreciated as I would prefer to have an understanding of the root cause. :-). |
Are you using a repository that extends DynamicProxyable? It doesn't look like it. Does the error occur in findCartsByGlobalUserId(), in someFiltering() or in scrub()? Can you show the method where the error occurs? |
Thanks for mentioning The issue can be fixed by providing the bean class loader to |
MappingInstantiationException
for Abstract Classes using tasks ran on ForkJoinPool
The fix is going to be 4.4.11 and 5.0.5 |
Thank you @mp911de and @mikereiche for all your help |
And thanks for helping and getting a fix in! |
Release date for those versions is April 14 |
Hi, our team has had a really tough problem we been dealing with for some time and been trying to get to root cause. We have an issue with a particular service where it begins failing with the following exception:
Exception:
org.springframework.data.mapping.model.MappingInstantiationException
Message:
Stacktrace:
We have a standard @document with a list of an Abstract object like so:
private List<AbstractPaymentMethod<?>> paymentMethods;
The definition of the abstract class is:
An example of a class implementing the abstract class is:
We can't quite determine when exactly it happen but some of the versions that we're on are:
When app is initially deployed it runs fine for a while and then suddenly it begins throwing this error complaining specifically about our abstract class. Previous to these versions, we have been running fine up to 5 years so we're trying to determine if there was any change of behavior in the spring data commons area where we have to configure abstract classes differently. Any help would be greatly appreciated.
We are not using converters (@ReadingConverter / @WritingConverter) for this but simply just have an overall @document spring data couchbase entity class and use the standard PagingAndSortingRepository.
I imagine more data will be needed to help here but wanted to get convo started.
The text was updated successfully, but these errors were encountered: