views:

30

answers:

2

Here's the psudo-code for one of my methods:

1. Get PersistenceManager (pm)


2. pm.fetchObject1

3. pm.beginTransaction

4. pm.modifyObject1

5. pm.commit


6. pm.fetchObject2

7. pm.beginTransaction

8. pm.modifyObject2

9. pm.commit

however I get this error "can't operate on multiple entity groups in a single transaction..."

Do I have to put another line in between step 5 and 7 saying that I'm 'done' with object1, like to close it?

Thanks

A: 

Can't remember the solution to your main problem right now, but I do see another potential problem here - you are fetching your objects, then starting a transaction. Here's the potential problem with that:

2.  fetch BankAccount (let's say it has balance of $100)
2.5 Some other process modifies' the BankAccount to have a balance of $200
3.  begin transaction
4.  deposit $20 into BankAccount
5.  commit new balance ($120) into BankAccount

Whoops! you've just wiped out a whole bunch of money. what should have been a balance of 220 is now a balance of 120.

Peter Recore
+1  A: 

Although what you say should work, it may be a bug in the appengine. Meanwhile you can do the following (pseudo code) or have both entities object1 and object2 in the same entity groups. More on transactions and entity groups here

  1. Get PersistenceManager (pm)

  2. pm.currentTransaction (tx)

  3. tx.begin

  4. pm.fetchObject1

  5. modifyObject1

  6. tx.commit

  7. pm.close


  8. Get PersistenceManager (pm)

  9. pm.currentTransaction (tx)

  10. tx.begin

  11. pm.fetchObject2

  12. modifyObject2

  13. tx.commit

  14. pm.close

There's more discussion here

naikus
this is what I think I'll end up doing, thanks.
Applehund