All Product
s are not in the same entity group. Using JPA, Product
will be your entity kind.
JDO & JPA hide the underlaying datastore structure, which is hierarchical, just like your OS directories for example.
Think of an entity group as a data tree, where your root entity is, well, the tree root. To provide a clear exemple, I'll add a ProductDetail
child entity to Product. Let's say each product has many product details :
/** Root entity */
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;
// ...
/** Children entities */
@OneToMany
private List<ProductDetail> details;
}
@Entity
public class ProductDetail {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;
}
Your data would translate to the following hierarchical "schema" :
Product(id=1)
|__ProductDetail(id=2)
|__ProductDetail(id=3)
|__ProductDetail(id=7)
Product(id=4)
|__ProductDetail(id=5)
|__ProductDetail(id=6)
...
As you can see, if your Product
entities do not share a common parent entity (e.g. some other class holds a @OneToMany
reference to product), each of them is considered a root entity, which means that each product is in its own entity group.
Now what the docs say about transactions on entity groups :
(Using JPA, the difference between a "normal" and XG transaction is handled by the framework)
All Datastore operations in a transaction must operate on entities in
the same entity group if the transaction is a single group
transaction, or on entities in a maximum of five entity groups if the
transaction is a cross-group (XG) transaction.
This is why creating 10 new Product
(root) entities in a single datastore transaction will undoubtedly fail.
On the other hand, using the example above, you could create 20 ProductDetail
entities in the same transaction if they belong to the same Product
entity. (you could update the Product at the same time too)