在大型数据库中,我必须将节点类型的属性的数据类型从整数更改为字符串(即从42更改为“42”),以便也支持非数字ID。
我设法做到了
migration
属性本身和属性现在在数据库中具有预期的类型。
我使用Neo4j浏览器将查询结果显示为JSON的功能验证了这一点:
"graph": {
"nodes": [
{
"id": "4190",
"labels": [
"MyEntity"
],
"properties": {
"id": "225"
}
}
}
请注意,“id”属性不同于节点自己的(数字)id。
在相应的Spring-Data-Neo4j 4app中,我也将相应属性的类型从整数调整为字符串。我认为这已经足够了,但在第一次加载受影响的实体时,我现在收到:
org.neo4j.ogm.exception.MappingException: Error mapping GraphModel to instance of com.example.MyEntity
[...]
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Can not set java.lang.String field de.moneysoft.core.model.base.UriEntity.transfermarktId to java.lang.Integer
at org.neo4j.ogm.entity.io.FieldWriter.write(FieldWriter.java:43)
at org.neo4j.ogm.entity.io.FieldWriter.write(FieldWriter.java:68)
at org.neo4j.ogm.context.GraphEntityMapper.writeProperty(GraphEntityMapper.java:232)
at org.neo4j.ogm.context.GraphEntityMapper.setProperties(GraphEntityMapper.java:184)
at org.neo4j.ogm.context.GraphEntityMapper.mapNodes(GraphEntityMapper.java:151)
at org.neo4j.ogm.context.GraphEntityMapper.mapEntities(GraphEntityMapper.java:135)
... 122 common frames omitted
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field com.example.MyEntity.id to java.lang.Integer
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:764)
at org.neo4j.ogm.entity.io.FieldWriter.write(FieldWriter.java:41)
... 127 common frames omitted
我不知道Neo4j OGM存储任何类型的模型或数据类型(至少我在图中没有看到)。为什么它仍然相信我的属性是整数?
编辑:
迁移后的节点实体:
@NodeEntity
public class MyEntity
{
@Property
protected String name;
@Property
private String id;
}
我不知道任何其他相关代码。