Ray,
My suspicion is that usernames is not being fetched when you retrieve your
object. Collections are lazy loaded, though usernames must be getting
instantiated somewhere, otherwise you'd be getting a NullPointerException.
Can you try this version of addUsername and let me know what happens?
public void addUsername(String username) {
this.usernames.size(); // Should not be required, but this will
force this collection to load if the PersistenceManager is still open
if(!this.usernames.contains(
username)) {
this.usernames.add(username);
}
}
We are changing the behavior of collections, blobs, text fields and other
lazily loaded objects in 1.2.8 so that they are always eager loaded.
On Thu, Nov 26, 2009 at 8:00 AM, Ray <[email protected]> wrote:
> I am developing my App with GWT + GAE. today i met a strange thing.
>
> I am using Eclipse Galileo with GWT 1.7 and Google plugin 1.26.
> i have a class A, which is defined like the following one;
>
> public Class A {
> protected Long id;
> protected ArrayList<String> usernames;
>
> public ArrayList<String> getUsernames()
> return usernames;
> }
>
> public void setUsernames(ArrayList<String> usernames) {
> this.usernames = usernames;
> }
>
> public void addUsername(String username) {
> if(!this.usernames.contains(username)) {
> this.usernames.add(username);
> }
> }
> }
>
> on the Server side i have method called share.
>
> public void share(A a, String username) {
> PersistenceManager pm = PMF.get().getPersistenceManager();
> try {
> A a1 = pm.getObjectById(A.class, a.getId());
> a1.addUsername(username);
> System.out.println(tag.getUsernames());
> } catch (Exception e) {
> LOG.logp(Level.FINE, "WorkitemServiceImpl", "save",
> e.toString());
> } finally {
> pm.close();
> }
> }
>
> public void share(A a, String username) {
> PersistenceManager pm = PMF.get().getPersistenceManager();
> try {
> A a1 = pm.getObjectById(A.class, a.getId());
> a1.getUsernames().add(username);
> System.out.println(tag.getUsernames());
> } catch (Exception e) {
> LOG.logp(Level.FINE, "WorkitemServiceImpl", "save",
> e.toString());
> } finally {
> pm.close();
> }
> }
>
> when i call the method share on the client side, like share(a, "test"); the
> first one prints "[]", the second one prints "[test]". can anybody explain
> why this happens?
>
> thanks in advance!
>
> ray
>
> --
> 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]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
--
Ikai Lan
Developer Programs Engineer, Google App Engine
--
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.