我在调用RuntimeException
方法时收到Neo4jTemplate.getOrCreateRelationship()
并传入包含ArrayList
的属性。
java.lang.RuntimeException: Error retrieving or creating relationship for key testKey and value 999 with index TestRelIndex
这是我的代码:
Map<String, Object> relProperties = new HashMap<String, Object>();
List<String> tags = new ArrayList<String>();
tags.add("tag1");
tags.add("tag2");
relProperties.put("tags", tags);
Relationship rel = template.getOrCreateRelationship("TestRelIndex", "testKey", 999, userNode, itemNode, "shortlist", relProperties);
异常消息不具有描述性。经过一些调试后,我设法从org.neo4j.rest.graphdb.ExecutingResAPI.getOrCreateRelationship()
方法中获取以下错误消息,其中抛出了RuntimeException。
{"message":"Unknown property type on: [tag1, tag2], class java.util.ArrayList","exception":"IllegalArgumentException","fullname":"java.lang.IllegalArgumentException","stacktrace":["org.neo4j.kernel.impl.nioneo.store.PropertyStore.encodeValue(PropertyStore.java:582)","org.neo4j.kernel.impl.nioneo.xa.WriteTransaction.relAddProperty(WriteTransaction.java:1210)","org.neo4j.kernel.impl.persistence.PersistenceManager.relAddProperty(PersistenceManager.java:176)","org.neo4j.kernel.impl.core.NodeManager.relAddProperty(NodeManager.java:1156)","org.neo4j.kernel.impl.core.RelationshipImpl.addProperty(RelationshipImpl.java:69)","org.neo4j.kernel.impl.core.Primitive.setProperty(Primitive.java:436)","org.neo4j.kernel.impl.core.RelationshipImpl.setProperty(RelationshipImpl.java:29)","org.neo4j.kernel.impl.core.RelationshipProxy.setProperty(RelationshipProxy.java:129)","org.neo4j.server.rest.web.DatabaseActions$UniqueRelationshipFactory.initialize(DatabaseActions.java:1058)","org.neo4j.server.rest.web.DatabaseActions$UniqueRelationshipFactory.initialize(DatabaseActions.java:1033)","org.neo4j.graphdb.index.UniqueFactory.getOrCreateWithOutcome(UniqueFactory.java:241)","org.neo4j.server.rest.web.DatabaseActions.getOrCreateIndexedRelationship(DatabaseActions.java:1018)","org.neo4j.server.rest.web.RestfulGraphDatabase.addToRelationshipIndex(RestfulGraphDatabase.java:871)","java.lang.reflect.Method.invoke(Method.java:601)","org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)"]}
我尝试与Neo4jTemplate.createRelationshipBetween()
创建相同的关系,但它运行正常。这是否意味着Neo4jTemplate.getOrCreateRelationship()
不支持数组类型的属性?
答案 0 :(得分:1)
完全。您可以存储基元,但不能存储像Array
这样的对象。尝试使用自定义序列化程序,或将属性拆分为字符串数组而不是AraryList。
https://groups.google.com/forum/#!topic/neo4j/8SZDaGTELnk也提供了一些提示。