Skip to content
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

MappingException in Session.queryForObject when actualType extends objectType #671

Closed
nioertel opened this issue Oct 27, 2019 · 2 comments
Closed
Assignees
Labels

Comments

@nioertel
Copy link
Contributor

nioertel commented Oct 27, 2019

We're executing a query which may return a java.lang.Long or java.lang.Integer value. When calling Session.queryForObject we pass java.lang.Number as objectType.
The issue started occurring after upgrade from Spring Boot 2.1.5.RELEASE to 2.2.0.RELEASE.
It was introduced with commit 86f01ba.

Expected Behavior

Expectation is that super types of the actual result type can be used as result.

Current Behavior

The following exception is thrown from org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.queryForObject(ExecuteQueriesDelegate.java:97):
org.neo4j.ogm.exception.core.MappingException: Cannot map java.lang.Long to java.lang.Number. This can be caused by missing registration of java.lang.Number.

Possible Solution

The bug seems to be in org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.queryForObject(ExecuteQueriesDelegate.java:88).
Current code:
if (!next.getClass().isAssignableFrom(type)) {
Fix:
if (!type.isAssignableFrom(next.getClass())) {

Your Environment

  • OGM Version used: 3.2.1
  • Java Version used: Oracle JDK 1.8.0_202
  • Neo4J Version used: 3.2.3
  • Bolt Driver Version used (if applicable): 3.2.1
  • Operating System and Version: macOS 10.14.6
@nioertel
Copy link
Contributor Author

It would be great if there can be a version 3.2.2 soon so we can upgrade to spring boot 2.2.
On top of the tests in my pull request, I built the snapshot locally, overrode neo4j OGM version in our build and successfully verified that also our code seems to be working again.

@michael-simons michael-simons self-assigned this Oct 28, 2019
michael-simons added a commit that referenced this issue Oct 28, 2019
michael-simons pushed a commit that referenced this issue Oct 28, 2019
… returned from the database.

- Fix check if result type is assignable to provided generic type
- Add test to verify result type compatibility check

This fixes #671.
@michael-simons
Copy link
Collaborator

Thanks for the report and also the fix, that is very much appreciated. I have also backported the test to 3.1.x, to ensure the desired behaviour there as well.

We'll see that we realize a patch in time for the Spring Boot 2.2.1 release which is due soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants