0

I am working with v2.2.3 of Neo4J and Spring Neo4j Data SDN 4 I want to return a few properties of a node using a cypher query and map them into attributes of a POJO.My function in Spring data repository looks something like this

@Query(
"MATCH(n:ServiceProvider{profileStatus:{pStatus},currentResidenceState:{location}}) RETURN n.name,n.currentResidenceAddress ,n.employmentStatus,"
                       + "n.idProofType,n.idProofNumber 
ORDER BY n.registrationDate DESC SKIP{skip} LIMIT {limit}")
List<AdminSearchMapResult> getServiceProviderRecords(
       @Param("pStatus")String pStatus,
       @Param("location")String location,
       @Param("skip") int skip,@Param("limit")int limit);

I get an error like

Scalar response queries must only return one column. Make sure your cypher query only returns one item.

I think its because of the fact that I cant bundle all the returned attributes into a view that can map into the POJO

If I return the node itself and map it into a POJO it works

Kindly guide

Christophe Willemsen
  • 19,399
  • 2
  • 29
  • 36
milan garg
  • 21
  • 6

1 Answers1

2

This can be done using @QueryResult

Annotate the AdminSearchMapResult POJO with @QueryResult. For example:

@QueryResult
public class AdminSearchMapResult {

  String name;
  String currentResidenceAddress;
...

}

Optionally annotate properties with @Property(name = "n.idProofType") if the alias is different from the field name.

Luanne
  • 19,145
  • 1
  • 39
  • 51
  • Thanks will revert with the results – milan garg Jul 23 '15 at 03:41
  • @QueryResult annotation could not be imported – milan garg Jul 23 '15 at 04:50
  • I am using the following dependencies in pom.xml – milan garg Jul 23 '15 at 04:51
  • org.neo4j - neo4j-ogm- 1.1.0 org.springframework.data- spring-data-neo4j - 4.0.0.M1 org.neo4j.app - neo4j-server - 2.2.3 org.springframework.data - spring-data-commons - 1.10.0.RELEASE spring-libs-snapshot Spring http://repo.spring.io/libs-snapshot neo4j http://m2.neo4j.org/content/repositories/releases false – milan garg Jul 23 '15 at 04:55
  • Please use RC1 instead of M1. You need only use org.springframework.data spring-data-neo4j 4.0.0.RC1 – Luanne Jul 23 '15 at 07:34
  • I have used the RC1 version now .But the problem is that in my Neo4JConfiguration file I get error java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories.repositoryBaseClass() at the time of server startup.The code contains annotations Configuration EnableNeo4jRepositories(basePackages = "com.app.repository") EnableTransactionManagement – milan garg Jul 28 '15 at 11:14
  • I am referring to the following doc http://docs.spring.io/autorepo/docs/spring-data-neo4j/4.0.x/reference/pdf/spring-data-neo4j-reference.pdf – milan garg Jul 28 '15 at 11:21
  • Do you have any dependencies on spring data commons? Please share your dependencies – Luanne Jul 28 '15 at 15:41
  • org.neo4j neo4j-ogm 1.1.0 org.springframework.data spring-data-neo4j 4.0.0.RC1 – milan garg Jul 28 '15 at 16:24
  • org.springframework spring-aop 4.0.3.RELEASE org.springframework.data spring-data-jpa 1.6.0.RELEASE org.springframework spring-aop org.springframework.data spring-data-commons 1.10.0.RELEASE – milan garg Jul 28 '15 at 16:25
  • Please try spring-data-commons 1.11.0.BUILD-SNAPSHOT Include spring-libs-snapshot Spring http://repo.spring.io/libs-snapshot – Luanne Jul 29 '15 at 05:01