繁体   English   中英

Spring Data Neo4j图形存储库不起作用

[英]spring data neo4j graph repository not working

我是春季数据neo4j的新手,并且在GraphRepository中遇到一些错误/问题。

我首先有这个:

import guru.springframework.domain.Product;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.repository.Neo4jRepository;

public interface ProductRepository extends GraphRepository<Product> {

   Product findById(Long id);

    Product deleteById(Long id);
}

但是阅读一些文档,该存储库已经提供了这种方法。 我不需要写它们。

这是我的产品领域

import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;

import java.math.BigDecimal;


@NodeEntity
public class Product {

    @GraphId
    private Long id;
    private String description;
    private BigDecimal price;
    private String imageUrl;

    //getters and setters
}

这是我的考试课

   @Test
    public void testPersistence() {

        productRepository.deleteAll();
        //given
        Product product = new Product();
        product.setDescription(PRODUCT_DESCRIPTION);
        product.setImageUrl(IMAGE_URL);
        product.setPrice(BIG_DECIMAL_100);

        //when
        productRepository.save(product);

        //then
        Assert.assertNotNull(product.getId());

        //Product newProduct = productRepository.findById(product.getId()).orElse(null);


        Product newProduct = productRepository.findById(182L);

未检测到findById

错误

那是正常的吗?

这是我的pom.xml

从Spring Data Neo4j 5.x开始,您应该扩展Neo4jRepository而不是GraphRepository

GraphRepository曾经存在于旧版本中。 您依赖于spring-boot 2.0.0.M7 ,该过渡可依赖于SDN 5。

如果您的IDE识别了GraphRepository则项目设置中会出现另一个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM