user246160
user246160

Reputation: 1397

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 = groupdesc;

 }

 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;


 }

}

Upvotes: 0

Views: 1795

Answers (2)

Peter Recore
Peter Recore

Reputation: 14187

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:

Upvotes: 0

msw
msw

Reputation: 43487

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

Upvotes: 1

Related Questions