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

Cannot return a set from a query with Neo4j (hashcode ResultColumn problem) [DATAGRAPH-325] #888

Closed
spring-projects-issues opened this issue Jan 6, 2013 · 2 comments
Labels
in: core Issues in core support type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Jan 6, 2013

Peter Zeidman opened DATAGRAPH-325 and commented

I cannot return a Set from a query due to a bug in QueryResultProxy. Example code:

public interface FruitSaladRepository extends GraphRepository<FruitSalad> {
    @Query("START fruitsalad=node:FruitSalad(uniqueName={0}) "
        + "MATCH fruitsalad-[:HAS_FRUIT]->fruit "
        + "RETURN fruitsalad,fruit")
    Set<QueryData> getFruit(String uniqueName);
    
    @MapResult
    public interface QueryData{
        @ResultColumn("fruitsalad")
        public FruitSalad getFruitSalad();

        @ResultColumn("fruit")
        public Fruit getFruit();        
    }
}

Error upon calling getFruit():

java.lang.NullPointerException
java.lang.NullPointerException
at org.springframework.data.neo4j.support.conversion.QueryResultProxy.invoke(QueryResultProxy.java:51)
at $Proxy46.hashCode(Unknown Source)
at java.util.HashMap.put(HashMap.java:389)
at java.util.HashSet.add(HashSet.java:217)
at org.neo4j.helpers.collection.IteratorUtil.addToCollection(IteratorUtil.java:324)

If I understand correctly, the error is caused by the Spring code attempting to add the resulting proxy object to a HashMap. This causes hashCode to be called on the proxy object, but because it doesn't have @ResultColumn on the hashcode, it fails.

This has previously been reported on the forum at the link I provided, but I don't think a JIRA issue was created for it.

Thanks,
Peter


Affects: 2.1

Reference URL: http://forum.springsource.org/showthread.php?122523-Neo4j-Issue-using-Cypher-query-and-MapResult-ResultColumn-(NullPointerException)

Referenced from: commits 436a10b, 65422a5, b765195, 763fe56

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 6, 2013

Michael Hunger commented

Thanks for reporting it. Can you for now use an Iterable<QueryData> or a List

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 6, 2013

Peter Zeidman commented

Thanks Michael, that workaround saved the day

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core support labels Dec 31, 2020
@spring-projects-issues spring-projects-issues added this to the 2.2.2 milestone Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant