DatastoreException:给定的键没有字符串名称值,但尝试转换为字符串

问题描述 投票:1回答:1

使用Spring Java存储库在GCP数据存储中将@Id类型从Long更改为String。

DatastoreDataException
org.springframework.cloud.gcp.data.datastore.core.mapping.DatastoreDataException: The given key doesn't have a String name value but a conversion to String was attempted
spring google-cloud-platform google-cloud-datastore
1个回答
0
投票
我提供了每个示例的2个屏幕截图

数字identer image description here

字符串nameenter image description here

所以当你这样说:

使用Spring Java存储库在GCP数据存储中将@Id类型从Long更改为String。

您实际上做了什么?

听起来您刚刚在ORM中更改了模型定义。这实际上并不会更改已存储在数据存储中的任何内容,只会影响以后的新实体。听起来好像,您正在获取具有id的实体,但是您的模型定义期望它们具有name

您将需要某种数据迁移工作来将它们全部转换。由于将密钥更改为使用name,因此即使转换为正确的单词也不会创建正确的单词。您必须在此过程中删除使用id的旧实体。

您还必须将具有关键属性的所有其他实体也更新为这种类型。

© www.soinside.com 2019 - 2024. All rights reserved.