Hi
I have a class, which has list of other objects. Looks like this

@PersistenceCapable
public class Category
{
        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        private Key key;
        @Persistent
        private String name;
        @Persistent
        private String url;
        @Persistent(mappedBy = "category")
        private List<Item> items = new LinkedList<Item>();
        ........
}

@PersistenceCapable
public class Item
{
        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        private Key key;
        @Persistent
        private Category category;
        ...........
}

When I create new category I save it in the store:
Category category = new Category(req.getParameter("categoryName"),
req.getParameter("categoryUrl"));
try
{
        pm.makePersistent(category);
}
finally
{
        pm.close();
}

When I need a category I get it by key:
PersistenceManager pm = PMF.get().getPersistenceManager();
Category category = pm.getObjectById(Category.class, categoryKey);

And here I have a problems. The items field is null. I thought it was
because of items type was List (interface). So I've changed it to
LinkedList, but it changed nothing.
Another thought was also that the list was empty so it wasn't saved. I
added one item at the moment of category creation like this|:
Category category = new Category(req.getParameter("categoryName"),
req.getParameter("categoryUrl"));
category.getItems().add(new Item());
try
{
        pm.makePersistent(category);
}
finally
{
        pm.close();
}
Still it doesn't save.
As far as I understand it's a usual way of using linked lists. Should
it work like that or I should save each item separately and then
retrieve them directly from the store?

-- 
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 google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to