0
votes

I have two entities, parent and child, that have a OneToMany relationship. The parent has an @Owned annotation for the child class. There is no relationship back. (from child to parent)

@Entity
public class Parent {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Owned
    @OneToMany(fetch = FetchType.LAZY)
    private Set<Child> children;

    .........

}


@Entity
public class Child {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key id;

    public String value;

    .........

    public int hashCode() {
         ... based on this.value ...
    }

    public boolean equals(Object o) {
         ... based on this.value ...
   }

}

Question 1: Does this setup resemble an entity group where Parent is the ancestor? The following two statements do return an equal Key:

- child.getId().qv.getId().getParent()
- KeyFactory.createKey("Parent", parent.getId())

Question 2: Should the following code take about ten seconds to execute? It runs in about 223 milliseconds:

for(int i = 0; i < 10; i++) {
    em.getTransaction().begin();

    parent = em.find(Parent.class, parentId);

    child = new Child("value" + i);
    parent.addChild(child)

    em.merge(parent)

    em.getTransaction().commit();
}

The reason why I think it should take 10 seconds is because of this statement in the Google App Engine Documentation:

"However, the rate at which you can write to the same entity group is limited to 1 write to the entity group per second."

in https://developers.google.com/appengine/docs/java/gettingstarted/usingdatastore

Thanks

2

2 Answers

2
votes

Are you running on the local development server or production? The local development server doesn't mimic the performance characteristics of production exactly.

The limit is placed as a guideline. You may get better performance than that in bursts. However, if you try a significantly long period of high writes, you will get exceptions.

The performance limit on the datastore writes won't slow down your code execution. They'll throw exceptions when the transactional writes fail. Make sure you have some exception handler to check whether this occurs.

0
votes

Q1: Parent indeed looks like the ancestor.

Q2: Why would it take 10 seconds? I see nothing that would imply that this MUST be the case. So my answer to this is no.