Class and Field Annotations

Each object saved by Slim3 Datastore becomes an entity in the App Engine Datastore. The entity's kind is derived from the simple name of the class (inner classes use the $ path without the package name). Each persistent field of the class represents a property of the entity, with the name of the property equal to the name of the field (with case preserved).

To declare a Java class as model, give the class a @Model annotation. For example:

import org.slim3.datastore.Model;

@Model
public class Employee {
   
// ...
}

Fields of the data class are stored in the datastore. A persistent field must have getter and setter methods.

import java.util.Date;

// ...
   
private Date hireDate;

public Date getHireDate() {
return hireDate;
}

public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
}

To declare a field as not persistent (it does not get stored in the datastore, and is not restored when the object is retrieved), give it a @Attribute(persistent = false) annotation.

import java.util.Date;
import org.slim3.datastore.Attribute;


// ...
@Attribute(persistent = false)
   
private Date hireDate;

The type of a field can be any of the following. These are described in detail below.

  • one of the core types supported by the datastore
  • a Collection (java.util.List, java.util.Set and java.util.SortedSet) of a core datastore type
  • an instance or Collection of instances of a Serializable class

A data class must have one field dedicated to storing the primary key of the corresponding datastore entity. A key field must be com.google.appengine.api.datastore.Key. A key use a @Attribute(primaryKey = true) annotation:

import com.google.appengine.api.datastore.Key;
import org.slim3.datastore.Attribute;

// ...
   
@Attribute(primaryKey = true)
   
private Key key;

// ... accessors ...

Next...

Continue to Meta data of model.

Comments