views:

36

answers:

1

I have tried to insert/update multiple entites on a single transaction but no avail. It always throws IllegalArgumentException.

I wanted to do something like this.

Transaction tx = pm.currentTransaction();
tx.begin();

for(int i=0;i<10;i++) {
    SampleEntity entity = new SampleEntity(i);
    pm.makePersistent(entity);
}

tx.commit();

If this is not possible, is there a workaround to make it work? Thanks.

+1  A: 

The docs on Transactions should be helpful here, especially the section on Entity Groups.

Entity groups tell App Engine to store multiple entities in the same node of the datastore -- otherwise, a transaction would require tons of cross-node communication and be nearly impossible to get right.

Entity groups are primarily used for parent-child relationships, so that a child entity can be updated in the same transaction as is parent.

Jason Hall
Hi ImJasonH, thanks for the reply.I wanted to store 1MB per record. In my example above, im going to insert a total of 10MB (1MB each entity).If im going to use parent child relationship, the whole parent and child entity is limited to 1MB right? there is no way to insert 10MB of data?
Link
I'm not sure if the entity size limit is by entity or entity group, and the docs aren't very clear on this either. Why not try it and see if it works?
Jason Hall
I tried it and it works :) thanks for leading me the right path.
Link