Re: [appengine-java] Re: storing unowned objects(one to many) in datastore
Hi, I can not create entity group because both are both classes can exists independently, It can be unowned relation between them. I want both should be stored in datastore or none of these(Atomic behavior ) . If one entity is not stored other entity must not store in datastore . Didier's suggestion looks good , but i did not try . * * On Thu, Dec 16, 2010 at 8:35 PM, WillSpecht wrote: > Why do you want to store both in the same transaction? To me, it seems > transactions are used to guarantee two things happen. eg. you don't > want to delete one record without making sure the a log of deleted > records is updated. Transactions are also used to prevent collisions, > eg. I don't want two users adding to a counter at the same time and > one of their adds is lost. > > It seems neither of these is likely. It is unlikely that a new Person > will be created and before the system can save their mobile, some > other user will try and edit it. It is also unlikely that either of > these will fail and not fail gracefully. If you try and add a user in > one transaction then try to add a mobile in a second transaction > either both will succeed or fail. Same outcome as a single > transaction. Or one of the two fails and you simply try it again or > delete the one that didn't fail and inform the user. > > If you really need a single transaction you can put both items in the > same entity group using a key builder. > > You can see an example here under Creating Entities With Entity Groups > http://code.google.com/appengine/docs/java/datastore/transactions.html > > Dec 15, 10:16 pm, Didier Durand wrote: > > Hi, > > > > If they don't belong to the same entity group, you will raise an > > exception by trying to store 2 objects in a single transaction. > > > > 2 ways to handle that: > > > >a) you make Mobile belong to same entity group as Person so you'll > > be able to store both in a single transaction. I understand in your > > question that you can't go this way. > >b) you store one let's say Person in first transaction and during > > this transaction, you start a task as part of the transaction: "You > > can enqueue a task as part of a datastore transaction, such that the > > task is only enqueued—and guaranteed to be enqueued—if the transaction > > is committed successfully. Tasks added within a transaction are > > considered to be a part of it and have the same level of isolation and > > consistency." as said inhttp:// > code.google.com/appengine/docs/java/taskqueue/overview.html#Ta... > > > > Hope it helps > > > > didier > > > > On Dec 15, 8:26 am, kartik kudada wrote: > > > > > Can we store two unowned objects(one to many) in datastore in a single > > > transaction. > > > For example - We have > > > > > public class Person { > > > @PrimaryKey > > > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > > > private Long id; > > > > > @Persistent > > > private String name; > > > > > @Persistent > > > private List mobileIds = new ArrayList(); > > > > >// > > > //. > > > } > > > > > public class Mobile { > > > > > @PrimaryKey > > > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > > > private Key mobileId; > > > > > // ... > > > // > > > > > } > > > > > I want to store these two objects in datastore in single transaction so > that > > > relation can be made in between both objects. > > > Tell me if any other solution is there ? > > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine for Java" group. > To post to this group, send email to > google-appengine-j...@googlegroups.com. > To unsubscribe from this group, send email to > google-appengine-java+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/google-appengine-java?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-j...@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
[appengine-java] Re: storing unowned objects(one to many) in datastore
Why do you want to store both in the same transaction? To me, it seems transactions are used to guarantee two things happen. eg. you don't want to delete one record without making sure the a log of deleted records is updated. Transactions are also used to prevent collisions, eg. I don't want two users adding to a counter at the same time and one of their adds is lost. It seems neither of these is likely. It is unlikely that a new Person will be created and before the system can save their mobile, some other user will try and edit it. It is also unlikely that either of these will fail and not fail gracefully. If you try and add a user in one transaction then try to add a mobile in a second transaction either both will succeed or fail. Same outcome as a single transaction. Or one of the two fails and you simply try it again or delete the one that didn't fail and inform the user. If you really need a single transaction you can put both items in the same entity group using a key builder. You can see an example here under Creating Entities With Entity Groups http://code.google.com/appengine/docs/java/datastore/transactions.html Dec 15, 10:16 pm, Didier Durand wrote: > Hi, > > If they don't belong to the same entity group, you will raise an > exception by trying to store 2 objects in a single transaction. > > 2 ways to handle that: > > a) you make Mobile belong to same entity group as Person so you'll > be able to store both in a single transaction. I understand in your > question that you can't go this way. > b) you store one let's say Person in first transaction and during > this transaction, you start a task as part of the transaction: "You > can enqueue a task as part of a datastore transaction, such that the > task is only enqueued—and guaranteed to be enqueued—if the transaction > is committed successfully. Tasks added within a transaction are > considered to be a part of it and have the same level of isolation and > consistency." as said > inhttp://code.google.com/appengine/docs/java/taskqueue/overview.html#Ta... > > Hope it helps > > didier > > On Dec 15, 8:26 am, kartik kudada wrote: > > > Can we store two unowned objects(one to many) in datastore in a single > > transaction. > > For example - We have > > > public class Person { > > @PrimaryKey > > �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > > private Long id; > > > @Persistent > > private String name; > > > @Persistent > > private List mobileIds = new ArrayList(); > > > // > > //. > > } > > > public class Mobile { > > > �...@primarykey > > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > > private Key mobileId; > > > // ... > > // > > > } > > > I want to store these two objects in datastore in single transaction so that > > relation can be made in between both objects. > > Tell me if any other solution is there ? -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-j...@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
[appengine-java] Re: storing unowned objects(one to many) in datastore
Hi, If they don't belong to the same entity group, you will raise an exception by trying to store 2 objects in a single transaction. 2 ways to handle that: a) you make Mobile belong to same entity group as Person so you'll be able to store both in a single transaction. I understand in your question that you can't go this way. b) you store one let's say Person in first transaction and during this transaction, you start a task as part of the transaction: "You can enqueue a task as part of a datastore transaction, such that the task is only enqueued—and guaranteed to be enqueued—if the transaction is committed successfully. Tasks added within a transaction are considered to be a part of it and have the same level of isolation and consistency." as said in http://code.google.com/appengine/docs/java/taskqueue/overview.html#Tasks_Within_Transactions Hope it helps didier On Dec 15, 8:26 am, kartik kudada wrote: > Can we store two unowned objects(one to many) in datastore in a single > transaction. > For example - We have > > public class Person { > @PrimaryKey > �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > private Long id; > > @Persistent > private String name; > > @Persistent > private List mobileIds = new ArrayList(); > > // > //. > } > > public class Mobile { > > �...@primarykey > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > private Key mobileId; > > // ... > // > > } > > I want to store these two objects in datastore in single transaction so that > relation can be made in between both objects. > Tell me if any other solution is there ? -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-j...@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.