我有一个图形数据库,节点Person和Prod(电影)之间的关系ACTED_IN指向Prod。我使用spring引导数据neo4j将数据从基于云的dd数据库获取到我的应用程序。我不能在我的代码中反映这种ACTED_IN关系,使其具有关系属性,如“字符”指向一个字符串列表,说明Person在电影中扮演了谁。这是我迄今为止最好的尝试,我得到的错误是:
Neo4j云中的ACTED_IN查询结果示例:
*(:Person {primaryProfession: ["actress"], birthYear: 1929, deathYear: 2003, name: "Queta Claver", nconst: "nm0165424"})-[:ACTED_IN {characters: "["Mimi"]", order: "1"}]->(:Prod {runtimeMinutes: 85, titleType: ["movie"], genres: ["Comedy", "Musical"], originalTitle: "La bella MimÃ", tconst: "tt0054675", startYear: 1961, title: "Beautiful Mimi"})*
人员类别:
@Node
public class Person {
@Id @GeneratedValue
private Long identity;
private int birthYear;
private int deathYear;
private String name;
private String[] primaryProfession;
public int getBirthYear() {
return birthYear;
}
public int getDeathYear() {
return deathYear;
}
public String getName() {
return name;
}
public String[] getPrimaryProfession() {
return primaryProfession;
}
}
产品类别:
@Node
public class Prod {
@Id @GeneratedValue
private Long identity;
private String[] genres;
private String originalTitle;
private String title;
private String[] titleType;
private int runtimeMinutes;
private int startYear;
@Relationship(type = "ACTED_IN", direction = Relationship.Direction.INCOMING)
private List<ActedIn> actors;
private Prod() {
// Empty constructor required as of Neo4j API 2.0.5
};
public Long getIdentity(){
return identity;
}
public String getTitle(){
return title;
}
public String getOriginalTitle(){
return originalTitle;
}
public String[] getGenres() {
return genres;
}
public String[] getTitleType() {
return titleType;
}
public int getRuntimeMinutes() {
return runtimeMinutes;
}
public int getStartYear() {
return startYear;
}
public List<ActedIn> getActors() {
return actors;
}
}
应反映关系的类:
@RelationshipProperties
public final class ActedIn {
@Id @GeneratedValue
private Long identity;
@TargetNode
private Person person;
private Prod prod;
@Property("characters")
private List<String> characters;
@Property("order")
private String order;
public ActedIn(Person person, List<String> characters, String order) {
this.person = person;
this.characters = characters;
this.order = order;
}
public Long getIdentity() {
return identity;
}
public Person getPerson() {
return person;
}
public List<String> getCharacters() {
return characters;
}
public String getOrder() {
return order;
}
public Prod getProd() {
return prod;
}
}
我用来获取产品详细信息的端点:
@RequestMapping(value = "/movie/{identity}", method = RequestMethod.GET)
public @ResponseBody Prod getMovieById(@PathVariable Long identity) {
Prod prod = prodDao.findProdByIdentity(identity);
return prod;
}
以及我从neo4j驱动程序中得到的错误的前几行:
Error mapping Record<{prod: {Prod_ACTED_IN_Person: [{__internalNeo4jId__: 8203, birthYear: 1931, deathYear: NULL, primaryProfession: ["actress"], __elementId__: "8203", name: "Carroll Baker", Prod__relationship__Person: relationship<19>, __nodeLabels__: ["Person"]}], runtimeMinutes: 113, __internalNeo4jId__: 7222, titleType: ["movie"], genres: ["Drama", "Romance", "War"], originalTitle: "Bridge to the Sun", __elementId__: "7222", startYear: 1961, title: "Bridge to the Sun", __nodeLabels__: ["Prod"]}}>
2023-06-22T21:29:49.767+02:00 ERROR 6416 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.data.mapping.MappingException: Error mapping Record<{prod: {Prod_ACTED_IN_Person: [{__internalNeo4jId__: 8203, birthYear: 1931, deathYear: NULL, primaryProfession: ["actress"], __elementId__: "8203", name: "Carroll Baker", Prod__relationship__Person: relationship<19>, __nodeLabels__: ["Person"]}], runtimeMinutes: 113, __internalNeo4jId__: 7222, titleType: ["movie"], genres: ["Drama", "Romance", "War"], originalTitle: "Bridge to the Sun", __elementId__: "7222", startYear: 1961, title: "Bridge to the Sun", __nodeLabels__: ["Prod"]}}>] with root cause
org.neo4j.driver.exceptions.value.NotMultiValued: STRING is not iterable
如果我删除
演员
从Prod,端点正在返回我从数据库中要求的Prod,没有任何问题。