Spring 数据Neo4j如何聚合

Spring Data Neo4j how to aggregate

我正在尝试做我认为应该是一项非常基本的任务,但我正在努力。我的代码如下:

@Query("match (x:Package) where x.houseAirwayBill = {self}.houseAirwayBill return count(x)")
@JsonIgnore
Long pieces

@JsonProperty("total_pieces")
Long getPieces(){
    return pieces
}

然而,它只是抛出一个堆栈 strace 说它在想要获取地图时得到一个“1”...我一直在寻找其他方法来做到这一点,但我无法得到存储库在域对象中自动装配......我不知所措。没有人强制您要在域对象中进行聚合吗?

我的build.gradle

buildscript {
repositories {
    maven { url "https://repo.spring.io/libs-release" }
    mavenLocal()
    mavenCentral()
}
dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.10.RELEASE")
     }
   }

   apply plugin: "groovy"
   apply plugin: 'spring-boot'

   sourceCompatibility = JavaVersion.VERSION_1_8
   targetCompatibility = JavaVersion.VERSION_1_8

   version  = "1.4.38"

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
    maven { url "http://m2.neo4j.org/content/repositories/releases/"}
    maven { url "https://repo.spring.io/libs-release" }
    maven { url "https://repo.spring.io/libs-milestone" }
    maven { url 'http://repo.spring.io/snapshot' }
}

defaultTasks "clean", "processResources", "build"

dependencies {
    //groovy
    compile 'org.codehaus.groovy:groovy-all:2.4.0-rc-2'
//spring
compile("org.springframework.boot:spring-boot-starter-web"){
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile("org.springframework.boot:spring-boot-starter-jetty")
compile 'org.eclipse.jetty:jetty-servlet:9.3.0.M1'
compile 'org.springframework.boot:spring-boot-actuator:1.2.3.RELEASE'
//compile 'org.springframework.data:spring-data-rest-webmvc:2.3.0.RELEASE'
//compile 'org.springframework.hateoas:spring-hateoas:0.17.0.RELEASE'
compile('org.springframework.boot:spring-boot-starter-data-rest:1.2.3.RELEASE')
//compile 'org.springframework.data:spring-data-neo4j:3.3.0.RELEASE'
compile 'org.springframework.data:spring-data-neo4j-aspects:3.3.0.RELEASE'
//compile "org.neo4j:neo4j-rest-graphdb:2.0.1"
compile("org.hibernate:hibernate-validator")
compile 'javax.persistence:persistence-api:1.0.2'
compile 'org.springframework.data:spring-data-neo4j-rest:3.4.0.BUILD-SNAPSHOT'
compile 'org.springframework.data:spring-data-jpa:1.8.0.RELEASE'

//Jersey
compile 'org.glassfish.jersey.core:jersey-client:2.17'

//JsonSchema stuff
// Required if generating equals, hashCode, or toString methods
compile 'commons-lang:commons-lang:2.6'
// Required if generating JSR-303 annotations
compile 'javax.validation:validation-api:1.1.0.CR2'
// Required if generating Jackson 2 annotations
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.0'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.5.0'
// Required if generating JodaTime data types
compile 'joda-time:joda-time:2.2'

//Retrofit
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.retrofit:converter-jackson:1.2.2'


//logging
compile 'ch.qos.logback:logback-classic:1.1.2'
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.2.1'
}

processResources {
    expand(project.properties)
}

所以,在解决这个问题并查看文档之后,我这样做了:

    @Query("start item=node({self}) match (x:Package) where x.houseAirwayBill= item.houseAirwayBill return count(x)")
    @JsonIgnore
    def pieces

    @JsonProperty("total_pieces")
    @Transactional
     Long getPieces(){
        return pieces.get("count(x)") as Long
    }

start item=node({self}) 非常重要,因为它将自我引用绑定到我在这种情况下称为 Item 的参数。 getter NEEDS 也需要进行交易。我希望这会有所帮助,因为我无法在任何地方找到有关如何执行此操作的具体示例。

代码在 groovy 顺便说一句。