Make sure to close your PersistenceManager instance in getCategories().

Are you seeing the original error or a different stack trace?

- Jason

On Sun, Sep 6, 2009 at 7:06 AM, Bob L. <bob.net2...@gmail.com> wrote:

>
> 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 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