Spring Data Neo4j如何聚合

时间:2015-05-27 10:51:26

标签: neo4j spring-data spring-data-neo4j spring-hateoas

我试图做我认为应该是一项非常基本的任务但我正在进行蒸汽处理。我的代码如下:

@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)
}

1 个答案:

答案 0 :(得分:0)

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

    @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的参数。吸气剂需要也在交易中。我希望这有帮助,因为我无法找到一个关于如何在任何地方执行此操作的具体示例。

代码是groovy btw。