Oh mine! It occurred again. JDO looks quite fragile.
Is there any wrong with following code?
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Category {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private String name;
public Category() {
}
public Category(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
serverlet:
...
@SuppressWarnings("unchecked")
public List<Category> getCategories() {
String query = "select from " + Category.class.getName();
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
return (List<Category>) pm.newQuery(query).execute();
} catch (Exception ex) {
}
return null;
}
private void initializeCategories() {
List<Category> categories = this.getCategories();
if (categories == null || categories.isEmpty()) {
categories = new ArrayList<Category>();
Category category = new Category("Boys");
categories.add(category);
category = new Category("Girls");
categories.add(category);
PersistenceManager pm =
PMF.get().getPersistenceManager();
try {
pm.makePersistentAll(categories);
} finally {
pm.close();
}
}
}
...
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---