Hello,
I am trying to add Entites to the datastore, but nothing appears.
Where I am wrong ?
I have the Book Entity :
package fr.polytech.unice.ehitchhicker;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
private String author;
private int copyrightYear;
private Date authorBirthdate;
public Long getId() {
return id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getCopyrightYear() {
return copyrightYear;
}
public void setCopyrightYear(int copyrightYear) {
this.copyrightYear = copyrightYear;
}
public Date getAuthorBirthdate() {
return authorBirthdate;
}
public void setAuthorBirthdate(Date authorBirthdate) {
this.authorBirthdate = authorBirthdate;
}
}
And this servlet :
package fr.polytech.unice.ehitchhicker;
import java.io.IOException;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import javax.servlet.http.*;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
@SuppressWarnings("serial")
public class Connection extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
DatastoreService ds =
DatastoreServiceFactory.getDatastoreService();
Entity book = new Entity("Book");
book.setProperty("title", "The Grapes of ");
book.setProperty("author", "John Steinbeck");
book.setProperty("copyrightYear", 1939);
Date authorBirthdate = new GregorianCalendar(1902,
Calendar.FEBRUARY, 27).getTime();
book.setProperty("authorBirthdate", authorBirthdate);
ds.put(book);
Query q = new Query("Book");
q.addSort("title");
PreparedQuery pq = ds.prepare(q);
for (Entity result : pq.asIterable()) {
String title = (String) result.getProperty("title");
resp.getWriter().write(title + "\n");
}
}
}
The Query returns nothing. Can you show me where is the problem ?
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.