背景
Java实现neo4j图谱保存数据出错:
org.neo4j.driver.v1.exceptions.ClientException: Property values can only be of primitive types or arrays thereof
at org.neo4j.driver.internal.util.ErrorUtil.newNeo4jError(ErrorUtil.java:62)
...
原因
原因:neo4j只支持属性为基本类型或数组(元素只能为基本类型)。
具体的代码如下:
/**
* 图谱节点:动态增加属性
*/
@NodeEntity
public class GraphNode {
@Id
@GeneratedValue(strategy = Neo4JCustomIdStrategy.class)
private String id;
private String label;
private String labelName;
private String typeUri;
private Double x;
private Double y;
private boolean active;
@Properties
private Map<String, Object> icon = new HashMap<>();
@Properties
private Map<String, Object> properties = new HashMap<>();
@JsonIgnoreProperties({ "startNode", "endNode" })
@Relationship(type = "OWNS")
private List<Edge> edges = new ArrayList<>();
...Omit getter/setter method...
}
前台传来的json数据:
{
"color": "#7076ed",
"typeUri": "object.enterprise",
"size": 1,
"icon": {
"color": "#ebf1fc",
"scale": 1.5,
"contentStr": "F0F7",
"content": "",
"font": "FontAwesome"
},
"x": -3.01189349204656,
"active": false,
"y": 0.18748324093041402,
"label": "某公立医院",
"id": "16560",
"labelName": "单位",
"properties": [
{
"propertyKey": "entName",
"displayType": "C",
"propertyName": "企业(机构)名称",
"valueType": "string",
"propertyValue": [
"某公立医院"
],
"detail": true,
"queryType": "",
"statistics": false
},
{
"propertyKey": "uniscId",
"displayType": "C",
"propertyName": "统一社会信用代码",
"valueType": "string",
"propertyValue": [
"12370000495571840L"
],
"detail": true,
"queryType": "",
"statistics": false
},
{
"propertyKey": "dataSourcesId",
"displayType": "C",
"propertyName": "数据来源ID",
"valueType": "string",
"propertyValue": [
"4112"
],
"detail": false,
"queryType": "",
"statistics": false
},
{
"propertyKey": "dataSources",
"displayType": "C",
"propertyName": "数据来源",
"valueType": "string",
"propertyValue": [
"验证"
],
"detail": true,
"queryType": "",
"statistics": false
},
{
"propertyKey": "updateTime",
"displayType": "C",
"propertyName": "最后更新时间",
"valueType": "string",
"propertyValue": [
"2019-01-07 19:21:37"
],
"detail": true,
"queryType": "",
"statistics": false
}
]
}
可以看到json数据中properties保存时neo4j并不支持,这里提供一种解决思路:将实体类代码的properties属性改为String类型,以String类型保存,如果查询后返回到前台数据需要json,再使用fastjson等将String转换为json类型。
解决办法
更改实体类代码:
/**
* 图谱节点:动态增加属性
*/
@NodeEntity
public class GraphNode {
@Id
@GeneratedValue(strategy = Neo4JCustomIdStrategy.class)
private String id;
private String label;
private String labelName;
private String typeUri;
private Double x;
private Double y;
private boolean active;
@Properties
private Map<String, Object> icon = new HashMap<>();
private String properties;
@JsonIgnoreProperties({ "startNode", "endNode" })
@Relationship(type = "OWNS")
private List<Edge> edges = new ArrayList<>();
...Omit getter/setter method...
}
返回前台时转换代码:
JSON.parse(graphNode.getProperties());
最新评论
网飞没问题, 迪士尼+有解决方案么?
pp助手是安卓手机用的,根本下载用不来苹果
已解决
这样的话数据库里的结构为{"attachment":{"content":"xxx"}}, 要怎么才能变成{"content":"xxx"},从而使结构保持一致?
赞! make test不过的坑都写到的,谢谢楼主~
谢谢你
用了root用户还是一直502是怎么回事呢
student id 是空的