Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SpringDataNeo4J4-如何正确获取多对多实体的父级?_Neo4j_Spring Data Neo4j 4 - Fatal编程技术网

SpringDataNeo4J4-如何正确获取多对多实体的父级?

SpringDataNeo4J4-如何正确获取多对多实体的父级?,neo4j,spring-data-neo4j-4,Neo4j,Spring Data Neo4j 4,我在配对类上使用findByIngredientId时遇到这个问题,我无法在配对结果中获取成分(null)。但在调试模式下,该成分被提取。取配料的正确方法是什么? 我尝试使用loadAllByProperty,但它不起作用。它显示了下面的错误。 这是获取父节点的正确方法吗 com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->co

我在配对类上使用findByIngredientId时遇到这个问题,我无法在配对结果中获取成分(null)。但在调试模式下,该成分被提取。取配料的正确方法是什么? 我尝试使用loadAllByProperty,但它不起作用。它显示了下面的错误。 这是获取父节点的正确方法吗

com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]->com.food.model.neo.Ingredient["pairings"]->java.util.HashSet[0]->com.food.model.neo.Pairing["first"]-
这是我的课程:

@NodeEntity
public class Ingredient {

    private Long id;
    private String name;

    @Relationship(type = "HAS_CATEGORY", direction = "OUTGOING")
    private Category category;

    @Relationship(type = "PAIRS_WITH", direction = "UNDIRECTED")
    private Set<Pairing> pairings = new HashSet<>();
}

@NodeEntity
public class Category {

    @GraphId
    private Long id;

    private String name;
}

@RelationshipEntity(type = "PAIRS_WITH")
public class Pairing {

    Long id;

    @StartNode
    private Ingredient first;
    @EndNode
    private Ingredient second;

    private String affinity;
}
@NodeEntity
公共类成分{
私人长id;
私有字符串名称;
@关系(type=“HAS\u CATEGORY”,direction=“OUTGOING”)
私人类别;
@关系(type=“PAIRS_WITH”,direction=“UNDIRECTED”)
私有集对=新HashSet();
}
@节点性
公共类类别{
@格拉希德
私人长id;
私有字符串名称;
}
@RelationshipEntity(type=“配对”)
公共类配对{
长id;
@StartNode
私人成分优先;
@端节点
私人成分第二;
私有字符串亲和力;
}
这是我的控制器

@RequestMapping(value = "/foodStory", method = RequestMethod.GET)
public ModelAndView foodStory() {
    ModelAndView model = new ModelAndView("home");

    categoryRepository.deleteAll();
    ingredientRepository.deleteAll();
    pairingRepository.deleteAll();

    //Set up the categories
    Category meat = new Category("Meat");
    Category veg = new Category("Vegetable");
    categoryRepository.save(meat);
    categoryRepository.save(veg);

    //Set up two ingredients
    Ingredient chicken = new Ingredient("Chicken");
    chicken.setCategory(meat);
    ingredientRepository.save(chicken);

    Ingredient carrot = new Ingredient("Carrot");
    carrot.setCategory(veg);
    ingredientRepository.save(carrot);


    //Pair them
    Pairing pairing = new Pairing();
    pairing.setFirst(chicken);
    pairing.setSecond(carrot);
    pairing.setAffinity("Delicious");
    pairingRepository.save(pairing);

    Ingredient carrotIngredient = session.loadByProperty(Ingredient.class, "name", "Carrot");
    List<Pairing> pairingList = (List<Pairing>) session.loadAllByProperty(Pairing.class, "second", carrotIngredient);
    //Check the data in pairingList and the result :
    //expect to happens : pairings.first != null
    //what happens : pairings.first = null
    System.out.println("Done");
return model;
}
@RequestMapping(value=“/foodStory”,method=RequestMethod.GET)
公共模型和视图食品库(){
ModelAndView模型=新的ModelAndView(“主页”);
categoryRepository.deleteAll();
IngredEnterpository.deleteAll();
pairingRepository.deleteAll();
//设置类别
肉类类别=新类别(“肉类”);
蔬菜类=新类别(“蔬菜”);
分类保存(肉);
分类保存(蔬菜);
//设置两种成分
配料鸡肉=新配料(“鸡肉”);
鸡肉类(肉);
保存(鸡);
成分胡萝卜=新成分(“胡萝卜”);
胡萝卜类(蔬菜);
保存(胡萝卜);
//配对
配对=新配对();
配对。先排便(鸡);
配对。设定秒(胡萝卜);
结对;结对亲和力(“美味”);
pairingRepository.save(配对);
配料胡萝卜配料=session.loadByProperty(配料.class,“名称”,“胡萝卜”);
List pairingList=(List)session.loadAllByProperty(Pairing.class,“second”,second);
//检查pairingList中的数据和结果:
//预期发生:pairings.first!=null
//发生的情况:pairings.first=null
系统输出打印项次(“完成”);
收益模型;
}

当我尝试查看配对列表数据时,pairings.first返回空数据。

请您在上面的示例中添加一些注释,指定a)您期望发生的事情b)实际发生的事情I已经更新了问题并添加了一些注释。谢谢你,请你在上面的示例中添加一些注释,说明a)你期望发生的事情b)实际发生的事情我已经更新了问题并添加了一些注释。非常感谢。