[英]Neo4j-OGM/Spring-Data-Neo4j: Migrate property type from Integer to String
In a large database I have to change the data type of a property for a type of nodes from Integer to String (ie 42 to "42") in order to also support non-numerical IDs. 在大型数据库中,我必须将节点类型的属性的数据类型从“整数”更改为“字符串”(即42到“ 42”),以便也支持非数字ID。
I've managed to do the migration itself and the property now has the expected type in the database. 我已经设法进行了迁移,并且该属性现在在数据库中具有预期的类型。 I have verified this using the Neo4j-Browsers ability to show the query result as JSON: 我已经使用Neo4j-Browsers功能将查询结果显示为JSON进行了验证:
"graph": {
"nodes": [
{
"id": "4190",
"labels": [
"MyEntity"
],
"properties": {
"id": "225"
}
}
}
Note that the "id" property is different from the node's own (numerical) id. 请注意,“ id”属性与节点自己的(数字)id不同。
In the corresponding Spring-Data-Neo4j 4app, I adjusted the type of the corresponding property from Integer to String as well. 在相应的Spring-Data-Neo4j 4app中,我也将相应属性的类型从Integer调整为String。 I expected that to be enough, however upon first loading an affected entity I now receive: 我期望这样就足够了,但是,在第一次加载受影响的实体时,我现在收到:
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
I am not aware of Neo4j-OGM storing any kind of model or datatype (at least I don't see it in the graph). 我不知道Neo4j-OGM存储任何类型的模型或数据类型(至少我在图中看不到)。 Why does it still believe that my property is an Integer? 为什么仍然相信我的财产是整数?
Edit: Node Entity after migration: 编辑:迁移后的节点实体:
@NodeEntity
public class MyEntity
{
@Property
protected String name;
@Property
private String id;
}
I am not aware of any other relevant code. 我不知道任何其他相关代码。
Well, if the error you see looks implausible, it probably is. 好吧,如果您看到的错误似乎难以置信,那就可能是。 After a good nights sleep, I realized that I had connected to the wrong database instance: Not the one that was migrated and that I was looking at in the browser, but another one that contained an unmigrated state. 经过一夜安眠后,我意识到我已连接到错误的数据库实例:不是一个正在迁移的并且正在浏览器中查看的数据库实例,而是另一个包含未迁移状态的实例。
After connecting to the correct instance, everything worked as expected! 连接到正确的实例后,一切都按预期工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.