Google App Engine JDO 与 HashMap 子字段的持久性
我有一个父类,我想在其中存储一个 HashMap。但是,每次我尝试修改该 HashMap 时都会收到以下错误:
PM org.datanucleus.store.appengine.MetaDataValidator checkForIllegalChildField 警告:无法验证一对多关系 com.monsters.server.MonUser.monsters
知道那是什么吗?这是代码:
这是 Parent 类的代码
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class MonUser {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent(serialized="true", mappedBy = "owner")
@Element(dependent = "true")
private HashMap<String,Monster> monsters;
……
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Monster {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private MonUser owner;
。
我已经尝试了 appengine 页面上有关关系的所有内容,但似乎没有任何帮助 任何信息都会非常有帮助!
PS 我已经让它可以与 ArrayLists 等一起使用,但不能与 hashmaps、hashtables、maps 等一起使用。如果这有帮助的话。
I have a parent class and I want to store a HashMap within it. However, every time I try to modify that HashMap I get the following error:
PM org.datanucleus.store.appengine.MetaDataValidator checkForIllegalChildField
WARNING: Unable to validate one-to-many relation com.monsters.server.MonUser.monsters
Any idea what that's about? Here is the code:
This is the code to the Parent class
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class MonUser {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent(serialized="true", mappedBy = "owner")
@Element(dependent = "true")
private HashMap<String,Monster> monsters;
...
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Monster {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private MonUser owner;
...
I've tried everything on the appengine page on relationships and nothing seems to help. Any info would be extremely helpful!
P.S. I've gotten it to work with ArrayLists and the like but not hashmaps, hashtables, maps, etc. If that helps at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JDO 仅支持以下集合:
java.util.ArrayList<...>
java.util.HashSet<...>
java.util.LinkedHashSet<...>
java.util.LinkedList<...>
java.util.List<...>
java.util.Set<。 ..>
java.util.SortedSet<...>
java.util.Stack<...>
java.util .TreeSet<...>
java.util.Vector<...>
Only the following Collections are supported by JDO:
java.util.ArrayList<...>
java.util.HashSet<...>
java.util.LinkedHashSet<...>
java.util.LinkedList<...>
java.util.List<...>
java.util.Set<...>
java.util.SortedSet<...>
java.util.Stack<...>
java.util.TreeSet<...>
java.util.Vector<...>
您可以使用以下方式持久化 HashMap:
@Persistent(serialized = "true", defaultFetchGroup="true")
请参阅 JDO - 嵌入类中的 HashMap
为了确保更改的持久性,您需要始终创建 HashMap 的新实例,请参见以下内容的结尾:
http://gae-java-persistence.blogspot.de/ 2009/10/serialized-fields.html
You can persist a HashMap with:
@Persistent(serialized = "true", defaultFetchGroup="true")
see JDO - HashMap within an embedded Class
To ensure persistence of changes you need to always create a new instance of HashMap see the end of:
http://gae-java-persistence.blogspot.de/2009/10/serialized-fields.html