无法通过长 ID 删除实体

Cannot Delete Entity by Long Id

我有这个 JUnit 代码:

@Test
public void test(){
  Entity e = new Entity(KeyFactory.createKey("Post", 1L))
  Key key = _ds.put(e); // _ds is native DatastoreService
  _ds.delete(KeyFactory.createKey("Post", 1L));
  Entity deleted = _ds.get(KeyFactory.createKey("Post", 1L));
  assertNull(deleted); // Not null, why?
}

Entity无法删除可能是什么问题?

我尝试使用 Key(由 put 生成)作为 Key to the:

_ds.delete(key); // won't delete also? 

(虽然我真的需要找出为什么它不会通过Long id删除)

我稍微修改了你的测试(编译),它对我有用:

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;

public class WhosebugTest {

    private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());

    @Before
    public void setUp() {
        helper.setUp();
    }

    @After
    public void tearDown() {
        helper.tearDown();
    }

    private final DatastoreService _ds = DatastoreServiceFactory.getDatastoreService();

    /**
     * 
     */
    @Test(expected = EntityNotFoundException.class)
    public void test28031142() throws EntityNotFoundException {
        Entity e = new Entity(KeyFactory.createKey("Post", 1L));
        Key key = _ds.put(e); // _ds is native DatastoreService
        _ds.delete(KeyFactory.createKey("Post", 1L));
        _ds.get(KeyFactory.createKey("Post", 1L));
    }
}