Hi Jason.

Thanks for your help. I can't get your suggestion to work - the data
either doesn't get saved or doesn't get retrieved because when I
retrieve the object it is always an empty map.
I have tried both setting entries into the existing HashMap and
setting the whole HashMap to a different, new HashMap every time I
change a value.
I am setting another string at the same time as setting the Map
values, and it is saved and retrieved fine.
I also tried dropping in another makePersistent call but that didn't
seem to make a difference.

My code is below. Any more suggestions? Is it possible it works on the
AppEngine but not in the SDK?

Thanks for your help,

Graham.

// Copyright (c) 2004 Graham Lea. All rights reserved.

import java.util.Map;
import java.util.HashMap;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.IdGeneratorStrategy;

import com.google.appengine.api.datastore.Key;

/**
 * <p></p>
 *
 * @author Graham Lea
 * @version $Revision:$
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable = "true")
public class
MyPersistentChildClass
{
   @PrimaryKey
   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
   private Key key;

   @Persistent
   private String name;

   @Persistent
   private String label;

   @Persistent(serialized = "true", defaultFetchGroup = "true")
   private Map<String, Byte> values = new HashMap<String, Byte>();

   @Persistent
   private String testString;

   public
   MyPersistentChildClass()
   {}

   public
   MyPersistentChildClass(String name, String label)
   {
      this.name = name;
      this.label = label;
   }

   public Key
   getKey()
   {
      return key;
   }

   public String
   getName()
   {
      return name;
   }

   public void
   setName(String name)
   {
      this.name = name;
   }

   public String
   getLabel()
   {
      return label;
   }

   public void
   setLabel(String label)
   {
      this.label = label;
   }

   public void
   setValue(String criterion, byte value)
   {
      values.put(criterion, value);
   }

   public void
   removeValue(String criterion)
   {
      values.remove(criterion);
   }

   public Byte
   getValue(String criterion)
   {
      return values.get(criterion);
   }

   public Map<String, Byte>
   getValues()
   {
      return values;
   }

   public void
   setValues(Map<String, Byte> values)
   {
      this.values = values;
   }


   public String
   toString()
   {
      return "MyPersistentChildClass@" + hashCode() +
         "[name=" + name +
         ", label=" + label +
         ", values=" + values +
         "]";
   }

   public void setTestString(String testString)
   {
      this.testString = testString;
   }

   public String getTestString()
   {
      return testString;
   }
}

On Aug 15, 2:54 am, "Jason (Google)" <apija...@google.com> wrote:
> First, keep in mind that joins aren't supported by App Engine's datastore --
> you'll have to use owned or unowned relationships 
> instead:http://code.google.com/appengine/docs/java/datastore/relationships.html
>
> You should be able to get this to work using the following:
>
> @Persistent(serialized="true")
> private Map<String, Byte> values = new HashMap<String, Byte>();
>
> Let me know if you have any more questions on this.
>
> - Jason

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to