google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

Always stores class names in arrays of Embedded entities. #358

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
(What version are you using? (Morphia/Driver/MongoDB): 
morphia-1.00-SNAPSHOT.jar, mongo-2.6.5a.jar, mongod-2.0.1. I use Morphia module 
for Play! Framework, play-morphia-1.2.4b)

As far as I observed, class names for embedded entities are always stored 
within them when their arrays are fields of a @Entity-annotated class.

My use case is below.

=====
@Entity(value = "fbfriend", noClassnameStored = true)
public class FacebookFriendsList extends Model {
     @Embedded
     private FacebookFriend[] list;

     private Date updated;
     ...//getter-setters
}

@Embedded
public class FacebookFriend implements Serializable {
     public String name;
     ....
}
=====

On the `list` field of entities of `fbfriend` collection, all elements have 
classname stored (FacebookFriend.class).

Could you please try to reproduce?

Original issue reported on code.google.com by ahmetalp...@gmail.com on 11 Dec 2011 at 9:49

GoogleCodeExporter commented 9 years ago
Any updates on This, Scott?

Original comment by ahmetalp...@gmail.com on 19 Dec 2011 at 11:14

GoogleCodeExporter commented 9 years ago
It is better to store them as a List<FacebookFriend> and not an array for now. 
There seems to be issue with getting the type correctly from the array.

Original comment by scotthernandez on 6 Feb 2012 at 2:13

GoogleCodeExporter commented 9 years ago
Good to know that, thanks. I think speed/memory overhead of the List will cause 
much trouble than extra field in BSON document on large number of elements, in 
my opinion.

I have another question. What are the exact class type of List instances that 
are mapped back from the mongo documents. In other words, if I have a 
List<FacebookFriend> field will it be LinkedList, ArrayList or what when 
Morphia populated it? (assuming field type will be List, not ArrayList or 
LinkedList etc.)

Original comment by ahmetalp...@gmail.com on 6 Feb 2012 at 2:17

GoogleCodeExporter commented 9 years ago
I get this same behaviour with Lists even if I declare the concreteClass.

Original comment by t...@kioos.com on 20 Jun 2012 at 9:03

GoogleCodeExporter commented 9 years ago
I found that datastore.save() will not store the classname for the embedded 
collection but datastore.update() will. Any update on this issue?

Original comment by SeanZhou...@gmail.com on 29 Aug 2012 at 11:58

GoogleCodeExporter commented 9 years ago
I noticed the same thing as Sean.

Original comment by agiann...@kioos.com on 6 Nov 2012 at 4:55