开发者

Google App Engine transactional inserts in Java

开发者 https://www.devze.com 2022-12-21 08:25 出处:网络
I have tried to insert/update multiple entites on a single transaction but no avail. It always throws IllegalArgumentException.

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? 开发者_StackOverflow中文版Thanks.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消