Hi,

Take a look at 
http://code.google.com/appengine/docs/java/datastore/dataclasses.html
You can read in Section "Object Fields and Entity Properties" that:
"If a field's type is a Collection of a core data type or a
Serializable class and there are no values for the property on the
entity, the empty collection is represented in the datastore by
setting the property to a single null value. If the field's type is an
array type, it is assigned an array of 0 elements. If the object is
loaded and there is no value for the property, the field is assigned
an empty collection of the appropriate type. Internally, the datastore
knows the difference between an empty collection and a collection
containing one null value."

Try this:

public void add(B object) {
 if (list1 == null) {
 list1 = new ArrayList<B>();
 }
list1.add(object);
}

list1 (and list2) should be null only once.

Cheers,
Maciej

2009/9/7 elDoudou <the.edouard.merc...@gmail.com>:
>
> Hello.
>
> Maybe, I'm missing something obvious in the documentation, but I can't
> figure out why I cannot properly persist an entity which has two list-
> fields of the same type properly.
>
> I have the following persisted class:
>
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public final class A
>    implements Serializable
> {
>
> �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> �...@primarykey
>  private Key key;
>
> �...@persistent
>  private List<B> list1 =  new ArrayList<B>();
>
> �...@persistent
>  private List<B> list2 =  new ArrayList<B>();
>
> }
>
> where B is a very basic persisted class with only two persisted
> attributes (and of course, a key).
>
> Every time I persist an entity of A with 2 non-empty lists fields
> list1 and list2, once I request this instance (in another
> transaction), the list2 field is always empty.
>
> Does it mean that there are currently some restrictions on App Engine,
> which prevents to persist two collection attributes of the same type
> at the same time? Do I need to annotate the two fields in a specific
> way? I am running App Engine v1.2.5.
>
> Thank you so much for your help. Regards,
> Édouard
> >
>



-- 
Maciej Machulak
email: maciej.machu...@gmail.com
tel: +48 602 45 31 44
tel: +44 7999 606 767

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