Google app engine 通过Objectify在数据存储中保存递归对象

Google app engine 通过Objectify在数据存储中保存递归对象,google-app-engine,objectify,datastore,Google App Engine,Objectify,Datastore,我有一个用例,在这个用例中,我必须保存一个递归对象 两类: public class Item{ @Id private Long id; @Index private String name; @Index private String sku; @Index private Long shopId; @Index private String imageUrl=""; @Index private List<Long>optionIds; private List&l

我有一个用例,在这个用例中,我必须保存一个递归对象

两类:

public class Item{

@Id
private Long id;

@Index
private String name;

@Index
private String sku;

@Index
private Long shopId;
@Index
private String imageUrl="";

@Index
private List<Long>optionIds;

private List<Option> options;
}

public class Option{

@Id
private Long id;

@Index
private String name;

@Index
private String sku;

@Index
private Long shopId;
@Index
private String imageUrl="";

@Index
private List<Long>itemIds;

private List<Item> items;
}
公共类项目{
@身份证
私人长id;
@索引
私有字符串名称;
@索引
私有字符串sku;
@索引
私人长shopId;
@索引
私有字符串imageUrl=“”;
@索引
私有列表选项ID;
私人名单选择;
}
公共类选项{
@身份证
私人长id;
@索引
私有字符串名称;
@索引
私有字符串sku;
@索引
私人长shopId;
@索引
私有字符串imageUrl=“”;
@索引
私有列表项ID;
私人清单项目;
}
我也将这两个对象分别保存在两个不同的表中。 为此,我需要在项目模型的列表字段中添加@Ignore 和选项模型列表字段中的@Ignore

我现在需要一个完整的递归结构,并希望将其保存在另一个表中。 为此,我尝试了一种方法,将@IgnoreSave(IfNull.class)放在项目模型的列表字段和选项模型的列表字段上

但是,当我在完成上述操作后启动应用程序时,我得到了一个stackoverflow错误。错误类型如下:

java.lang.StackOverflowError
at java.security.AccessController.doPrivileged(Native Method)
at sun.reflect.annotation.AnnotationInvocationHandler.getMemberMethods(AnnotationInvocationHandler.java:284)
at sun.reflect.annotation.AnnotationInvocationHandler.equalsImpl(AnnotationInvocationHandler.java:196)
at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:63)
at com.sun.proxy.$Proxy9.equals(Unknown Source)
at java.util.Arrays.equals(Arrays.java:1869)
at com.googlecode.objectify.impl.translate.TypeKey.equals(TypeKey.java:60)
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:996)
at com.googlecode.objectify.impl.translate.Translators.get(Translators.java:115)
at com.googlecode.objectify.impl.translate.CreateContext.getTranslator(CreateContext.java:27)
at com.googlecode.objectify.impl.KeyMetadata.findKeyFields(KeyMetadata.java:78)
at com.googlecode.objectify.impl.KeyMetadata.<init>(KeyMetadata.java:50)
at com.googlecode.objectify.impl.translate.ClassTranslatorFactory.createEntityClassTranslator(ClassTranslatorFactory.java:64)
java.lang.StackOverflower错误
位于java.security.AccessController.doPrivileged(本机方法)
位于sun.reflect.annotation.AnnotationInvocationHandler.getMemberMethods(AnnotationInvocationHandler.java:284)
位于sun.reflect.annotation.AnnotationInvocationHandler.equalsImpl(AnnotationInvocationHandler.java:196)
位于sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:63)
位于com.sun.proxy.$Proxy9.equals(未知源)
位于java.util.Arrays.equals(Arrays.java:1869)
位于com.googlecode.objectify.impl.translate.TypeKey.equals(TypeKey.java:60)
位于java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:996)
位于com.googlecode.objectify.impl.translate.Translators.get(Translators.java:115)
位于com.googlecode.objectify.impl.translate.CreateContext.getTranslator(CreateContext.java:27)
在com.googlecode.objectify.impl.KeyMetadata.findKeyFields(KeyMetadata.java:78)
在com.googlecode.objectify.impl.KeyMetadata.(keymetada.java:50)
位于com.googlecode.objectify.impl.translate.ClassTranslatorFactory.createEntityClassTranslator(ClassTranslatorFactory.java:64)

我现在陷入困境,急需帮助。是否有其他解决方案通过objectify存储递归结构?

看起来您正试图保存两个相互引用的不同实体。为此,应使用
Ref
字段。递归对于这样的指针没有问题

通过指定
List
List
,您告诉Objectify您希望将这些东西递归地嵌入到单个实体中。Objectify不支持递归嵌入类(至少,目前还不支持)