@laserjim,

Did you figure this one out? I am running into the same issue.........



On Jul 7, 10:46 am, laserjim <laser...@gmail.com> wrote:
> Hey,
>
> I've attached some example code for reference:
>
> public class FooObject implements Serializable
> {
>     private final String name;
>     public FooObject(String name)
>     {
>         this.name = name;
>     }
>     public String toString()
>     {
>         return name;
>     }
>
> }
>
> @PersistenceCapable
> public class Entity
> {
>     @Element(serialized="true")
>     List<FooObject> foos = new ArrayList<FooObject>();
>
>     public void addFoo(FooObject foo)
>     {
>         foos.add(foo);
>     }
>     public List<FooObject> getFoos()
>     {
>         return foos;
>     }
>
> }
>
> Please let me know if you see the problem.
>
> Thanks!
>
> On Jul 7, 10:30 am, laserjim <laser...@gmail.com> wrote:
>
>
>
> > Hey,
>
> > I agree that your comments above are true for serialized fields, but I
> > can't find any documentation indicating such a behavior for
> > collections (I assume "supported collections" here, as described in
> > dataclasses#Collections).  My understanding is that a collection
> > should behave correctly (inserts, deletes, etc) unless the list its
> > self is serialized.  Can you provide a counter-example?
>
> > With regards to the article Max Ross wrote (very good article by the
> > way), the trick he used (where he made a copy in order to change the
> > reference) was intended to "dirty" the state when a member is
> > modified.  My FooObjects are immutable, so I don't think this applies
> > to me.  Max Ross' article is completely consistent with my
> > understanding of the documentation, but it's entirely possible I
> > missed something, so let me know if this doesn't sound right to you.
>
> > I BELIEVE the issue I'm running into is rooted in the exception I get
> > when trying to persist a populated instance of the list: "FooObject is
> > not a supported property type."  I'm just not understanding why it
> > isn't supported.  I would have expected that any serializable object
> > would be permitted, especially if the @Element(serialized="true")
> > annotation is specified.
>
> > Basically, I'm looking for a code fragment that demonstrates the
> > persistence of a collection of (more than one) non-standard
> > serializable objects.
>
> > Any ideas?
>
> > Thanks!
>
> > On Jul 7, 5:05 am, "l.denardo" <lorenzo.dena...@gmail.com> wrote:
>
> > > Hello,
> > > I guess your problem is the behavior of serialized fields (including
> > > collections of them, as far as I know), which is explained in Max
> > > Ross's post.
> > > Or something related to that.
>
> > > Anyway, some property fields are marked as "updated" and hence saved
> > > in the datastore only if you update the reference to the field, and
> > > they're not updated if you just use modifiers to operate on them.
> > > In practice, something like
>
> > >  ArrayList<Foo> list = "retrieve from datastore"
> > > list.add(Foo foo)
> > > close persistence manager
>
> > > Does not modify the list in the datastore, so if it's saved as an
> > > empty list at creation it remains empty.
> > > Doing
>
> > >  ArrayList<Foo> list = "retrieve from datastore"
> > >  ArrayList copy = new ArrayList(list);
> > >  copy.add(Foo foo)
> > >  list = copy;
> > > close PM
>
> > > Usually makes everything work, since the original list field is marked
> > > as "updated" and persisted.
> > > As far as I know this is true both for serialized fields and for many
> > > collections.
>
> > > Regards
> > > Lorenzo
>
> > > On Jul 7, 1:28 pm, laserjim <laser...@gmail.com> wrote:
>
> > > > Hello Lorenzo,
>
> > > > Thanks, but perhaps my question wasn't clear.  I'm trying to make a
> > > > list of serialized objects, NOT a serialized list of objects.
>
> > > > For instance, assuming FooObject implements Serializable...
>
> > > > @Element(serialized="true)
> > > > List<FooObject> foos = new ArrayList<FooObject>();
>
> > > > Unfortunately, the list is always empty.  Not quite sure why.
>
> > > > Thanks!
>
> > > > On Jul 7, 2:59 am, "l.denardo" <lorenzo.dena...@gmail.com> wrote:
>
> > > > > If you are using a serialized field you must add the serialized="true"
> > > > > clause to your annotation
>
> > > > > @Persistent(serialized="true")
> > > > > MySerializableObject serializable;
>
> > > > > Also notice that JDO does not automatically detect if you update only
> > > > > the inner fields of the object you save, so you must substitute it
> > > > > with a copy to have it persisted.
> > > > > See this post for a very good overview and an explanation of the fact
> > > > > above:
>
> > > > >http://groups.google.com/group/google-appengine-java/browse_thread/th...
>
> > > > > Regards
> > > > > Lorenzo
>
> > > > > On Jul 7, 1:33 am, laserjim <laser...@gmail.com> wrote:
>
> > > > > > Hello,
>
> > > > > > I'm still trying to persist a list of serializable objects. I would
> > > > > > expect this to be a standard collection as described 
> > > > > > here:http://code.google.com/appengine/docs/java/datastore/dataclasses.html...
>
> > > > > > FooObject is serializable, but my attempt gave me an exception:
> > > > > > FooObject is not a supported property type.
>
> > > > > > Everything works as expected if I replace my serializable class
> > > > > > (FooObject) with String.
>
> > > > > > How can I persist my list of FooObjects using JDO?
>
> > > > > > Thanks!

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

Reply via email to