Sessions are stored in a Memcache and that's the reason of the behaviour you described. The Memcache low-level API documentation says:
"The values returned from this API are mutable copies from the cache; altering them has no effect upon the cached value itself until assigned with one of the put methods. Likewise, the methods returning collections return mutable collections, but changes do not affect the cache." Imagine that the session object is not stored only on one server machine, but it needs to be distributed across all machines currenlty serving your application. So you must tell google app engine to re- distribute your modified session object. Vaclav On Apr 18, 4:19 am, Thomas <mylee...@gmail.com> wrote: > I have a class which has a counter field. > > public Class Foo implements Serializable { > private static final long serialVersionUID = 1L; > private int counter = 0; > // getter and setter omitted for simplicity > > } > > And in my program I put a Foo instance into HttpSession. > > HttpSession session = request.getSession(true); > Foo foo = (Foo)session.getAttribute("foo"); > if (foo==null) { > foo = new idv.Foo(); > session.setAttribute("foo", foo);} > > else > foo.setCounter(foo.getCounter()+1); > // continue processing with foo > > If session.setAttribute is executed, the session (and foo) is > serialized correctly and I can get the correct counter value at the > next request. But the counter value never gets increased at subsequent > requests. > > If I move the session.setAttribute call to behind the if-else block > to force execution in every request, the counter value increases > correctly. > > if (foo==null) > foo = new idv.Foo(); > else > foo.setCounter(foo.getCounter()+1); > session.setAttribute("foo", foo); > > I didn't see any doc about this. Is it a bug or a feature? > > -- > 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-j...@googlegroups.com. > To unsubscribe from this group, send email to > google-appengine-java+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/google-appengine-java?hl=en. -- 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-j...@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.