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.

SDN 6 custom query returns NULL

Hi there,

I am tring to return the subset of a domain entity (e.g ItemEntity) with a costom query using SDN 6 and SpringBoot 2.5. It is returning NULL without any error when I run the application.

I tried the same query in Neo4j Browser and works fine.

How that issue could be solved?

Below is a sample of the code where I face this issue

Thanks in advance for your help.
Amir

package org.website.gui.repository;

import org.website.gui.entity.ItemEntity;
import org.website.gui.projection.ItemSubset;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;

import java.util.Date;
import java.util.List;

public interface ItemRepository extends Neo4jRepository<ItemEntity, Integer> {

    @Query("MATCH (i:Item)"
            + " WHERE toLower (COALESCE(i.firstField,\" \")"
            + ") CONTAINS $englishKeyword"
            + " OR "
            + "COALESCE(i.secondField,\" \")"
            + "CONTAINS $russianKeyword"
            + " RETURN i"
    )
    List<ItemSubset> findWithKeywords(String englishKeyword, String russianKeyword);

1 ACCEPTED SOLUTION

Thank you @gerrit.meier .

I have checked the example and changed the spring-boot-strarter-parent version from 2.5.0 to 2.5.3.

    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.3</version> <!-- it was 2.5.0 -->
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

It is working now. I do not know how this upgrade was related to my issue!!!

Cheers,
A

View solution in original post

6 REPLIES 6

Would be really helpful to see your domain entity ItemEntity and the ItemSubset.
ItemSubset should be a valid projection as defined here reference documentation | projections.

Does this really return null or an empty list?

Hi @gerrit.meier

Thank you for your quick respond.

It returns an empty JSON Array. Something like [ ].

Please find code sample below:

package org.website.gui.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Property;
import org.springframework.data.neo4j.core.schema.Relationship;

import java.time.LocalDate;


@Node("Item")
@AllArgsConstructor
@Data
public class ItemEntity {
    @Id
    private final Integer id;
    private final LocalDate active_date;
    @Property("empty_sapce")
    private final String firstField;
    private final String secondField;
    private final String thirdField;
    @Relationship(type = "HANDLED_BY")
    private final TaskEntity task;
}

//--------ItemSubset--------

package org.website.gui.projection;

public interface ItemSubset {
    Integer getId();
    String getFirstField();
    String getSecondField();
}

Many thanks,
A

Could you checkout my example: neo4j-issues-examples/discourse-42200 at master · meistermeier/neo4j-issues-examples · GitHub
This works for me.

In your custom query you use toLower only on the english part not on the russian one. Might this be a problem?

Thank you @gerrit.meier !
I have changed the custom query based on your suggestion but I still have the sam problem (no data returned).

How can I work around this problem?

Many thanks,
A

    @Query("MATCH (i:Item)"
            + " WHERE toLower (COALESCE(i.e_ops,\" \")"
            + ") CONTAINS $englishKeyword"
            + " OR "
            + "toLower (COALESCE(i.r_ops,\" \")"
            + ") CONTAINS $russianKeyword"
            + " RETURN i"
    )
    List<ItemSubset> findVariousKeywords(String englishKeyword, String russianKeyword);

I don't know what you are doing different to my example.
Maybe you can spot the difference between my code and your application around this place where you are facing the issue.

Thank you @gerrit.meier .

I have checked the example and changed the spring-boot-strarter-parent version from 2.5.0 to 2.5.3.

    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.3</version> <!-- it was 2.5.0 -->
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

It is working now. I do not know how this upgrade was related to my issue!!!

Cheers,
A