开发者

Google App Engine datastore-primary key

I've created a table in the Google App Engine Datastore. It contains the following FIELDS(GROUPNAME,GROUPID,GROUPDESC). How do I set GROUPID as the primary key?

My code is as follows:

@Entity

@Table(name="group" , schema="PUBLIC")

public class Creategroup {

    @Basic

    private String groupname;

     @Basic   

    private  String groupid;

    @Basic

    private String groupdesc;



 public void setGroupname(String groupname) {

  this.groupname = groupname;

 }

 public String getGroupname() {

  return groupname;

 }

 public void setGroupid(String groupid) {

  this.groupid = groupid;

 }

 public String getGroupid() {

  return groupid;

 }

 public void setGroupdesc(String groupdesc) {

  this.groupdesc = gr开发者_运维百科oupdesc;

 }

 public String getGroupdesc() {

  return groupdesc;

 }

 public Creategroup(String groupname, String groupid, String groupdesc
   ) {

  // TODO Auto-generated constructor stub
    this.groupname = groupname;

    this.groupid = groupid;

    this.groupdesc = groupdesc;


 }

}


You set the primary key with the @PrimaryKey annotation as described in the Defining Data Classes documentation.


megala, the page you (tried) to link to in your comment to msw's answer contains the following text that should answer your question. I think if you read that entire page carefully you'll be able to persist some data successfully.

A data class must have a public or protected default constructor and one field dedicated to storing the primary key of the corresponding datastore entity. You can choose between 4 different kinds of key fields, each using a different value type and annotations. (See Creating Data: Keys for more information.) The simplest key field is a long integer value that is automatically populated by JPA with a value unique across all other instances of the class when the object is saved to the datastore for the first time. Long integer keys use a @Id annotation, and a @GeneratedValue(strategy = GenerationType.IDENTITY) annotation:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜