Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-29-2021 09:11 PM
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);
Solved! Go to Solution.
08-01-2021 01:06 AM
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
07-29-2021 11:33 PM
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?
07-30-2021 12:15 AM
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
07-30-2021 04:41 AM
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?
07-30-2021 12:01 PM
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);
07-30-2021 10:37 PM
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.
08-01-2021 01:06 AM
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
All the sessions of the conference are now available online