更新时间:2023-09-14 10:10:40
只要实体是没有其他父母的父实体,上述代码就会工作。
如果您有一个子实体,您也必须迁移父键。
例如:
键parentKey = key.getParent();
Key newParentKey = KeyFactory.createKey(parentKey.getKind(),parentKey.getId());
只有您可以使用此代码
Key newKey = KeyFactory.createKey(newParentKey,childKey.getKind(),childKey.getId());
这个例子只适用于一个家长,如果你有多个家长,你将不得不使用这个代码几次。
I have started to migrate from our M/S application to HRD. I wonder if you can recommend me how to convert old string encoded keys to new ones.
I know that string encoded keys holds the application name, although I am not certain if there are other details which I need to take care of. In addition, I could not find any forum-post, which has Java's code example of converting "string encoded keys" which looks quite strange to me (only python forums discuss it).
I will appreciate any help on this matter.
By the way I thought to run the following, although I'm afraid it will not work or cover all aspects:
private static String convertKey(String encodedKey) {
Key key = KeyFactory.stringToKey(encodedKey);
Key newKey = KeyFactory.createKey(key.getKind(), key.getId());
return KeyFactory.keyToString(newKey);
}
Thanks! Uri
The above code will work as long as the Entity is a Parent entity with no other Parents. If you have a Child Entity you will have to migrate the parent key as well.
For Example:
Key parentKey = key.getParent();
Key newParentKey = KeyFactory.createKey(parentKey.getKind(), parentKey.getId());
Only then you can use this code
Key newKey = KeyFactory.createKey(newParentKey,childKey.getKind(), childKey.getId());
This example applies for only one parent, if you have multiple parents you will have to use this code a few times.