Thank You your example it is very helpful!

Do you have any performance problems?

I am concerned about 30 put request limit.

I am considering your solution or storing tree as JSON string or both.
I need unique ID for each tree node.

Cheers, Max

On Sep 23, 4:26 pm, Ian Marshall <[email protected]> wrote:
> Hi Max,
>
> I have a tree structure using JDO, where each instance of the entity
> has one parent and zero or more children. These relationships cannot
> be performed by GAE/J currently due to outstanding bugs in self-
> referential owned relationships.
>
> So I model these relationships as unowned, using each entity's Long ID
> as key. Each entity also has an entity group parent (in my example
> below, the same instance of my class EntityGroupRoot). By using a
> common entity group parent, one can ensure that all entities are in
> the same entity group (if one wants that).
>
> The drawback for the work-around is that the unowned parental and
> child relationships have to be kept up to date manually by your app.
>
> My example of a working persistent entity class follows.... Do let me
> know if this helps you succeed.
>
> Regards,
>
> Ian
>
> package [...];
>
> import java.io.Serializable;
> import java.util.ArrayList;
> import javax.jdo.annotations.IdGeneratorStrategy;
> import javax.jdo.annotations.IdentityType;
> import javax.jdo.annotations.PersistenceCapable;
> import javax.jdo.annotations.Persistent;
> import javax.jdo.annotations.PrimaryKey;
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION,
>  detachable = "true")
> public class ItemCategory implements Serializable
> {
>   private static final long serialVersionUID = 1L;
>
>   
> //////////////////////////////////////////////////////////////////////////////
>   // This block is required since this entity has an entity group
> root.
>   // It does not work with MySQL, so we use an alternative for that
> database.
>   // We have the getter method for getting the encoded key here for
> convenience.
>   //
>
>   @PrimaryKey
>   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>   @Extension(vendorName="datanucleus", key="gae.encoded-pk",
> value="true")
>   private String sEncodedKey;
>
>   @Persistent
>   @Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
>   private Long loID;
>
>   public String getEncodedKey()
>   {
>     return sEncodedKey;
>   }
>
>   //
>   
> //////////////////////////////////////////////////////////////////////////////
>
>         /*
>   
> //////////////////////////////////////////////////////////////////////////////
>   // This block is required for testing with MySQL only, and will not
> work
>   // for Google BigTable.
>   //
>
>   @PrimaryKey
>   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>   private Long loID;
>
>   //
>   
> //////////////////////////////////////////////////////////////////////////////
>         */
>
>   @Persistent
>   private EntityGroupRoot egrEntityGroupParent;
>
>   @Persistent
>   private Long loParentID;
>
>   @Persistent
>   private ArrayList<Long> liChildIDs = new ArrayList<Long>();
>
>   @Persistent
>   private String sName;
>
>   @Persistent
>   private Boolean bActive;
>
>   
> //////////////////////////////////////////////////////////////////////////////
>   // Getter methods (except getting the encoded key,
>   // which is grouped with its field for convenience).
>   //
>
>   public Long getID()
>   {
>     return loID;
>   }
>
>   public EntityGroupRoot getEntityGroupParent()
>   {
>     return egrEntityGroupParent;
>   }
>
>   public Long getParentID()
>   {
>     return loParentID;
>   }
>
>   public ArrayList<Long> getChildIDs()
>   {
>     ArrayList<Long> alIDs = liChildIDs;
>
>     if (alIDs == null)
>       alIDs = new ArrayList<Long>();
>
>     return alIDs;
>   }
>
>   public String getName()
>   {
>     return sName;
>   }
>
>   public boolean getActive()
>   {
>     boolean bResult = false;
>
>     if ((bActive != null) && bActive.booleanValue())
>       bResult = true;
>
>     return bResult;
>   }
>
>   //
>   
> //////////////////////////////////////////////////////////////////////////////
>
>   
> //////////////////////////////////////////////////////////////////////////////
>   // Setter methods
>   //
>
>   public void setEntityGroupParent(EntityGroupRoot entityGroupParent)
>   {
>     egrEntityGroupParent = entityGroupParent;
>   }
>
>   public void setParentID(Long parentID)
>   {
>     loParentID = parentID;
>   }
>
>   public void setChildIDs(ArrayList<Long> childIDs)
>   {
>     liChildIDs = childIDs;
>   }
>
>   public void setName(String name)
>   {
>     sName = name;
>   }
>
>   public void setActive(boolean active)
>   {
>     bActive = new Boolean(active);
>   }
>
>   //
>   
> //////////////////////////////////////////////////////////////////////////////
>
>   
> //////////////////////////////////////////////////////////////////////////////
>   // Other methods
>   //
>
>   public void addChildID(Long loChildID)
>   {
>     if (liChildIDs == null)
>       liChildIDs = new ArrayList<Long>();
>
>     liChildIDs.add(loChildID);
>   }
>
>   //
>   
> //////////////////////////////////////////////////////////////////////////////
>
> }
>
>
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to