cancel
Showing results for 
Search instead for 
Did you mean: 

Spring returns empty array

kksdsfgrg
Node

I have simple project that has to connect nodes Train and Station. Connection between them is called STOPS. When I'm trying to execute query with this relationship I get an empty array. But when I execute this query in Neo4j Desktop I get expected result.

Here is my code:

public interface TrainRepository extends Neo4jRepository<Train, Long> {

    @Query("MATCH (u)<-[r:STOPS]-(m:Station) RETURN u,collect(r),collect(m)")
    Collection<Train> getAllTrains();
}
@NodeEntity
public class Train {

    @Id
    @GeneratedValue
    private Long id;
    private Integer number;
    private Integer number_of_carriages;

    public List<Station> getStations() {
        System.out.println(stations);
        return stations;
    }

    public void setStations(List<Station> stations) {
        this.stations = stations;
    }

    @Relationship(type = "STOPS", direction = Relationship.INCOMING)
    private List<Station> stations;

...
}
1 REPLY 1

gerrit_meier
Neo4j
Neo4j

Just for clarification: You get an empty Train collection or Station collection within a returned Train?

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.