尝试在 Morphia on Play 中使用 @Embedded 对象时出现以下错误。
A java.lang.StackOverflowError has been caught, null Hide trace
java.lang.StackOverflowError
at java.util.LinkedHashMap.init(LinkedHashMap.java:223)
at java.util.HashMap.(HashMap.java:210)
at java.util.LinkedHashMap.(LinkedHashMap.java:181)
at org.bson.BasicBSONObject.(BasicBSONObject.java:39)
at com.mongodb.BasicDBObject.(BasicDBObject.java:42)
at com.google.code.morphia.mapping.Mapper.toDBObject(Mapper.java:435)
at com.google.code.morphia.mapping.Mapper.toDBObject(Mapper.java:430)
at com.google.code.morphia.mapping.EmbeddedMapper.writeCollection(EmbeddedMapper.java:68)
at com.google.code.morphia.mapping.EmbeddedMapper.toDBObject(EmbeddedMapper.java:30)
这是由于尝试保存以下类的实例引起的:
@Entity
public class Profile extends Model
{
@Embedded
public class ObjectPermission
{
public String type;
public ArrayList<String> viewable;
public ArrayList<String> editable;
}
public String _sfid;
public String _type;
@Embedded
public ArrayList<ObjectPermission> object;
}
我们正在尝试通过以下方式保存它:
@Test
public void TestFullProfileSave()
{
Profile p = new Profile();
p._sfid = "0123456789101213145";
p._type = "entitlements";
ObjectPermission objPerm = p.new ObjectPermission();
objPerm.type = "Account";
objPerm.viewable = new ArrayList<String>();
objPerm.viewable.add("field1");
objPerm.viewable.add("field2");
objPerm.editable = new ArrayList<String>();
objPerm.editable.add("field3");
objPerm.editable.add("field4");
p.object = new ArrayList<ObjectPermission>();
p.object.add(objPerm);
p.save();
}
我有一种感觉它是 ArrayLists 但不知道为什么因此我感到困惑。提前致谢。
保罗