cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Properties of relationship entities return null in custom @Query

Hello,

I'm trying to model a dependency graph with these nodes. But i have problems to get a result in relationship nodes while querying custom @Query's.

Artefact:

  • Artefact (Label)
  • name: String

Version

  • Version (Label)
  • version: String
  • relationship to Artefact
@NodeEntity
public class Artefact {

    // Properties
    @Id
    @GeneratedValue
    private Long id;

    private String name;

    public Artefact() {}

    public Artefact(String name) {
        this.name = name;
    }

// + getter and setter
@NodeEntity
public class Version {

    // Properties
    @Id
    @GeneratedValue
    private Long id;

    private String version;

    @Relationship(type = "IS_VERSION")
    Artefact artefactsOf;

    public Version() {
    }

    public Version(String version) {
        this.version = version;
    }

// + getter and setter

The findAll() returns all properties of version and of artefactsOf included the names (Property of artefact).

public interface VersionRepository extends Neo4jRepository<Version, Long> {
    
    Iterable<Version> findAll();

but if i use a custom @Query, the artefactsOf return null.
Even with a very easy query, that actually should return the same as findAll.

    @Query("MATCH (v:Version) RETURN v")
    Iterable<Version> getAllVersions();

My results look like this:

*findAll()*

2X_a_a563fb1529562f885a44d1d86974481e5d2af450.png

*getAllVersions()*

2X_e_e3bd7c07e7a17cadf58ae97f7a8b4ab40dbb748a.png

What am i implementing wrong that every custom query only returns the properties of version, not the properties of artefact aswell?

I am implementing a large dependency graph of artefacts and version depending on each other. I should also use bigger queries to find nodes in a dependncy graph path. But even my small queries seems not to work.

I hope anyone can help me.

FYI - i am using these dependencies and Neo4j Server version: [4.1.1]

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-neo4j</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-rest</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
1 REPLY 1

I had a similar issue that was resolved by collecting each of the related nodes in the return.
For example your query would be something like:

MATCH (v:Version) 
OPTIONAL MATCH (v)-[is_version:IS_VERSION]->(artefact:Artefact)
RETURN v, collect(is_version), collect(artefact)

See this example on the sdn-rx github: https://github.com/neo4j/sdn-rx/blob/master/examples/imperative-web/src/main/java/org/neo4j/springfr...