Search code examples
javagoogle-app-enginegoogle-cloud-datastorejdo

Adding a child Element in GAE database


I have a persistent object that has a huge list of child elements. I'm trying to add a new element, but to retrieve the list i spent a lot of read operations. How can I add this elements without get the list?

I'm using something like this:

PersistenceManager pm = PMF.get().getPersistenceManager();
ObjectX obj= pm.getObjectById(ObjectX.class, id);
obj.getChildrenElements().add(newChild);

Solution

  • I am not sure there is another way to do this. Instead, maybe you could try to change the way you model the relationships. Thus, instead of keeping a list of children for each object, you could specify to each of the children a parent. This relationship doesn't have to be owned if you don't need the parents and the children to belong to the same entity group.

    Hope that helps!