views:

231

answers:

2

Hi,

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;


 }

}
A: 

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

msw
You'll also need to add @Persistent to every field you want saved in the datastore, and @PersistenceCapable to the class. It's all there in the link msw provided.
Jason Hall
hi created jpa application using the following link,"http://code.google.com/appengine/docs/java/datastore/usingjpa.html" in that they using @Basic,What i do
@jason, @Persistent is only needed on fields that are not persistent by default, which is most of them. see http://www.datanucleus.org/products/accessplatform_1_1/jdo/types.html for a list of types and their default persistence status
Peter Recore
A: 

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:

Peter Recore