我在配对类中使用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;
}
这是我的控制器。
@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;
}
当我尝试查看我的pairingList数据时,pairings.first返回空数据。