2
votes

when I am trying to return a node and a value with cypher query (movie and a user rating of that movie) the object in Set<> contains null values. If I execute Query in Neo4j browser, everything seems ok, but in code, there is null. I cannot figure out, where I am making a mistake.

see Set of movies and rating during debuging

Cypher Query in repository:

@Query("match(p1:Person {nick:{0}})-[r:RATED]->(m:Movie)\n" +
        "return m as movie,r.rate as rating")
Set<MovieRating> userRatedMoviesRatings(String nick);

MovieRating class:

@QueryResult
public class MovieRating {
   Movie movie;
   int rating;
}

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>dp.neo4j</groupId>
<artifactId>movies</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.3.RELEASE</version>
</parent>

<properties>
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.jexcelapi</groupId>
        <artifactId>jxl</artifactId>
        <version>2.6</version>
    </dependency>
    <!--<dependency>-->
        <!--<groupId>org.springframework.boot</groupId>-->
        <!--<artifactId>spring-boot-starter-security</artifactId>-->
    <!--</dependency>-->

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-releases</id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
    <repository>
        <id>neo4j</id>
        <name>Neo4j</name>
        <url>http://m2.neo4j.org/</url>
    </repository>
</repositories>

1
this is strange. are you sure your database does not contain movies with null titles? i would put a where clause on the cypher query in the repository to eliminate this possibility. maybe you are not connecting to the same db with the browser. - Mihai Raulea
Yeah I am sure, because I work with the same database with another queries, where I return only one object. For example the second query: @Query("match(p1:Person {nick:{0}})-[r:RATED]->(m:Movie)\n" + "return m") Set<Movie> userRatedMovies(String nick); And then: Set<MovieRating> movies2 = movieRepo.userRatedMoviesRatings(nick); Set<Movie> movies = movieRepo.userRatedMovies(nick); The movies2 set contains only null and movies contains nodes from the database. see: postimg.org/image/7lziukt01 postimg.org/image/kj9h4kzbl - user3904604

1 Answers

0
votes

my friend! I had the same issue. The problem is that probably your are working in the wrong repository. Set an appropriate class name here:

    public interface <someName> extends PagingAndSortingRepository<#YourCustomClass,Long>

Hope it will help to someone