繁体   English   中英

Neo4j-OGM / Spring-Data-Neo4j:将属性类型从Integer迁移到String

[英]Neo4j-OGM/Spring-Data-Neo4j: Migrate property type from Integer to String

在大型数据库中,我必须将节点类型的属性的数据类型从“整数”更改为“字符串”(即42到“ 42”),以便也支持非数字ID。

我已经设法进行了迁移,并且该属性现在在数据库中具有预期的类型。 我已经使用Neo4j-Browsers功能将查询结果显示为JSON进行了验证:

"graph": {
    "nodes": [
        {
            "id": "4190",
            "labels": [
                "MyEntity"
                ],
            "properties": {
                "id": "225"
            }
        }
    }

请注意,“ id”属性与节点自己的(数字)id不同。

在相应的Spring-Data-Neo4j 4app中,我也将相应属性的类型从Integer调整为String。 我期望这样就足够了,但是,在第一次加载受影响的实体时,我现在收到:

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;
}

我不知道任何其他相关代码。

好吧,如果您看到的错误似乎难以置信,那就可能是。 经过一夜安眠后,我意识到我已连接到错误的数据库实例:不是一个正在迁移的并且正在浏览器中查看的数据库实例,而是另一个包含未迁移状态的实例。

连接到正确的实例后,一切都按预期工作!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM