我很困惑使用自动生成的端点类.我想使用生成的端点将新对象插入数据存储区.但是,抛出一个例外.
fooEndpoint.insertFoo(foo); // throws null pointer exception
Run Code Online (Sandbox Code Playgroud)
我的实体类与此源中的给定示例类似:https: //developers.google.com/appengine/docs/java/datastore/jpa/overview.
这是我的实体:
@Entity
public class Foo {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Key ID;
Run Code Online (Sandbox Code Playgroud)
这是堆栈跟踪:
java.lang.NullPointerException
at org.datanucleus.api.jpa.JPAEntityManager.find(JPAEntityManager.java:318)
at org.datanucleus.api.jpa.JPAEntityManager.find(JPAEntityManager.java:256)
at com.FooEndpoint.containsFoo(FooEndpoint.java:150)
at com.FooEndpoint.insertFoo(FooEndpoint.java:96)
Run Code Online (Sandbox Code Playgroud)
另一方面,当我使用EntityManager persist方法时,我可以插入新对象.因为,这不会检查数据存储上是否存在.
我希望,classEndpoint插入方法应该保存对象并将自动键分配给ID字段.
或者我需要初始化ID字段.
这是自动生成的端点类insertFoo方法.
/**
* This inserts a new entity into App Engine datastore. If the entity already
* exists in the datastore, an exception is thrown.
* It uses HTTP POST method.
*
* @param foo the entity to be inserted.
* @return The inserted …Run Code Online (Sandbox Code Playgroud)