簡體   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