If you need more data from an entity than you can glean from its key prior to deleting it then retrieving the entity is ok but if you just need to delete it deleting it by key is much more efficient because there are no serialization costs as everything is done at the index level.
On Wed, Sep 1, 2010 at 2:42 AM, branflake2267 <branflake2...@gmail.com>wrote: > Hi Simon, > > This is what I do. First I load it, then delete it. > ThingJdo ttj2 = (ThingJdo) pm.getObjectById(ThingJdo.class, > ttj.getThingId()); > pm.deletePersistent(ttj2); > > > http://code.google.com/p/gwt-examples/source/browse/trunk/Core/src/org/gonevertical/core/server/jdo/data/ThingJdo.java#552 > - reference to my code > public boolean delete(ThingData thingData) { > > if (thingData == null) { > return false; > } > > if (thingData.getThingId() == 0) { > return false; > } > > // delete child objects that the thing owns first > deleteSub(thingData); > > ThingJdo ttj = new ThingJdo(sp); > ttj.setData(thingData); > > PersistenceManager pm = sp.getPersistenceManager(); > Transaction tx = pm.currentTransaction(); > boolean b = false; > try { > tx.begin(); > ThingJdo ttj2 = (ThingJdo) > pm.getObjectById(ThingJdo.class, ttj.getThingId()); > pm.deletePersistent(ttj2); > tx.commit(); > b = true; > } catch (Exception e) { > e.printStackTrace(); > b = false; > } finally { > if (tx.isActive()) { > tx.rollback(); > b = false; > } > pm.close(); > } > > return b; > } > > http://code.google.com/p/gwt-examples/ - more examples with demos and > source here. > > Hope that helps, > Brandon > > > On Aug 30, 11:34 am, Simon <guardianlampp...@gmail.com> wrote: > > Hi! > > > > I'm trying to delete an object by using the key id. > > > > I'm using an automatically generated key; > > > > <code> > > @PrimaryKey > > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > > private Key key; > > </code> > > > > What is the best way to delete an object with a specific id? > > > > I'm using Java, and had it working a while ago by doing; > > "WHERE __key__=Key('type', id) > > > > But now it tells me that = is an invalid operator. > > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine" group. > To post to this group, send email to google-appeng...@googlegroups.com. > To unsubscribe from this group, send email to > google-appengine+unsubscr...@googlegroups.com<google-appengine%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/google-appengine?hl=en. > > -- -- Jeff -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appeng...@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.