neo4j.ogm 使用 spring 引导应用程序的手动查询问题

manual query issue on neo4j.ogm using spring boot application

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>

 <groupId>org.springframework</groupId>
 <artifactId>NucleiAdmin</artifactId>
 <version>0.0.1-RELEASE</version>

 <name>NucleiAdmin</name>
 <url>http://maven.apache.org</url>

 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.2.2.RELEASE</version>
 </parent>
 <properties>
  <start-class>nuclei.Application</start-class>
  <java.version>1.7</java.version>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <tomcat.version>8.0.3</tomcat.version>
 </properties>

 <dependencies>
    
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  
  <dependency>
   <groupId>com.googlecode.json-simple</groupId>
   <artifactId>json-simple</artifactId>  
  </dependency>

  <!-- spring-data-neo4j -->
  <dependency>
   <groupId>org.springframework.data</groupId>
   <artifactId>spring-data-neo4j</artifactId>
   <version>4.0.0.RC2</version>
  </dependency>

  <dependency>
   <groupId>org.springframework.data</groupId>
   <artifactId>spring-data-neo4j-rest</artifactId>
   <version>3.0.1.RELEASE</version>
  </dependency>  

  <dependency>
   <groupId>org.neo4j</groupId>
   <artifactId>neo4j-cypher-compiler-2.1</artifactId>
   <version>2.1.5</version>
  </dependency>
    
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-jersey</artifactId>
  </dependency> 

  <!-- test scoped beans only -->
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>

  <dependency>
   <groupId>net.wimpi</groupId>
   <artifactId>telnetd-x</artifactId>
   <version>2.1.1</version>
  </dependency>
 </dependencies>


 <build>
  <finalName>NucleiAdmin</finalName>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
   <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
     <source>1.7</source>
     <target>1.7</target>
    </configuration>
   </plugin>

  </plugins>
 </build>

 <repositories>
  <repository>
   <id>spring-libs-snapshot</id>
   <name>Spring</name>
   <url>http://repo.spring.io/libs-snapshot</url>
  </repository>

  <repository>
   <id>neo4j</id>
   <url>http://m2.neo4j.org/content/repositories/releases</url>
   <snapshots>
    <enabled>false</enabled>
   </snapshots>
  </repository>

 </repositories>

 <packaging>war</packaging>
</project>

package nuclei.repository;

import java.util.Map;

import nuclei.domain.Blueprint;
import nuclei.domain.IaaSTemplate;

import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.stereotype.Repository;

/**
 * @author Karthikeyan
 *
 */
@Repository
public interface BlueprintRepository extends GraphRepository<Blueprint>{
 
 @Query("MATCH (Blueprint:Blueprint{isDeleted:'0'}) RETURN id(Blueprint) as id,Blueprint") 
 Iterable<Map<String,Object>> getTemplateBlueprints(); 

 @Query("MATCH (n { name: {0} }) SET n.position = {1}")   
 Blueprint createNewTemplate(String name,String position);
}

在我的项目中,我使用 spring boot、neo4j 和 org.neo4j.ogm 库在 spring boot 上集成 neo4j。我可以实现 GraphRepository 的 findone、findall 和 save 方法。但是当使用我自己的查询插入值时,它显示错误。我找不到问题的原因。我正在使用给定的查询`@Query("CREATE (n:Person { name : 'Andres', title : 'Developer' })")

package nuclei.service;

import java.util.Map;

import nuclei.domain.Blueprint;
import nuclei.domain.IaaSTemplate;
import nuclei.repository.BlueprintRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.stereotype.Service;

/**
 * @author Karthikeyan
 *
 */
@Service("blueprintService")
public class BlueprintServiceImpl extends GenericService<Blueprint> implements
  BlueprintService {

 @Autowired
 private BlueprintRepository blueprintRepository;

 @Override
 public GraphRepository<Blueprint> getRepository() {
  return blueprintRepository;
 }

 @Override
 public Iterable<Map<String, Object>> getTemplateBlueprints() {
  return blueprintRepository.getTemplateBlueprints();
 }

 @Override
 public Blueprint createNewTemplate(String name,String position){
  return blueprintRepository.createNewTemplate(name,position);
 }
}

@RequestMapping(value = "/createBp", method = RequestMethod.POST)
  public @ResponseBody BlueprintMessage createBP(
    @FormDataParam("name") String name,
    @FormDataParam("position") String position,
    final HttpServletResponse response) {
   ResponseStatus status = null;
  // Long blueprintId = Long.parseLong(id);
   Blueprint entity = null;
   try {
    entity = blueprintService.createNewTemplate(name, position);
    //entity.setBlueprint(blueprint);
    //entity.setIsDeleted("0");

    super.create(entity);
    status = new ResponseStatus(ResponseStatusCode.STATUS_OK, "SUCCESS");
   } catch (Exception e) {
    e.printStackTrace();
   }
   return new BlueprintMessage(status, entity);
  }

package nuclei.service;

import java.util.Map;

import nuclei.domain.Blueprint;
import nuclei.domain.IaaSTemplate;

/**
 * @author Karthikeyan
 *
 */
public interface BlueprintService extends MainService<Blueprint> {

 Iterable<Map<String, Object>> getTemplateBlueprints();
 
 Blueprint createNewTemplate(String name,String position);
}

请升级到SDN 4.0.0.RC2

以前的版本不允许修改通过 query() 执行的 Cypher 语句。