Google App Engine JDO persistence with HashMap child field
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.
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<...>
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
精彩评论