Can't inherit HashSet : generic is lost...
Hello,
In this example :
public class Authors extends HashSet<Author> {
// utils methods
}
@Entity
public class Book {
private Authors authors = new Authors();
}
BasicDAO.save(myBook) doesn't work with this exception :
java.lang.IllegalArgumentException: can't serialize class <package>.Author
at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:270)
at org.bson.BasicBSONEncoder.putIterable(BasicBSONEncoder.java:295)
....
I understood why : MappedField declare subType as null and isMongoType is true.
My question is :
- Why isMongoType is true ?
Thanks
Try annotating Authors with @Embedded
-------------------------------- * * _{ *name : "_Justin Lee", *
- title : *"Member of Technical Staff", twitter : "@evanchooly http://twitter.com/evanchooly_"_, web : [ "10gen.com", "antwerkz.com" ], location : "New York, NY" }
On Mon, Aug 5, 2013 at 12:52 PM, Duchatelle [email protected]:
Hello,
In this example :
public class Authors extends HashSet
{ // utils methods} @Entitypublic class Book { private Authors authors = new Authors();} BasicDAO.save(myBook) doesn't work with this exception :
java.lang.IllegalArgumentException: can't serialize class
.Author at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:270) at org.bson.BasicBSONEncoder.putIterable(BasicBSONEncoder.java:295) .... I understood why : MappedField declare subType as null and * isMongoType* is true.
My question is :
- Why isMongoType is true ?
Thanks
— Reply to this email directly or view it on GitHubhttps://github.com/mongodb/morphia/issues/502 .
Thanks for your response, but it doesn't work.
isMongoType is always true and set's values aren't converted into DBObject.
I get this warning :
The multi-valued field '<package>.Book.authors' is a possible heterogeneous collection. It cannot be verified. Please declare a valid type to get rid of this warning. null
OK. File and issue with a test case and I'll look in to it.
-------------------------------- * * _{ *name : "_Justin Lee", *
- title : *"Member of Technical Staff", twitter : "@evanchooly http://twitter.com/evanchooly_"_, web : [ "10gen.com", "antwerkz.com" ], location : "New York, NY" }
On Mon, Aug 5, 2013 at 1:09 PM, Duchatelle [email protected] wrote:
Thanks for your response, but it doesn't work.
isMongoType is always true and set's values aren't convert into * DBObject*.
I get this warning :
The multi-valued field '
.Book.authors' is a possible heterogeneous collection. It cannot be verified. Please declare a valid type to get rid of this warning. null — Reply to this email directly or view it on GitHubhttps://github.com/mongodb/morphia/issues/502#issuecomment-22120748 .
I made pull request with test case : #503
Thank you. I'll look in to as soon as I can.
-------------------------------- * * _{ *name : "_Justin Lee", *
- title : *"Member of Technical Staff", twitter : "@evanchooly http://twitter.com/evanchooly_"_, web : [ "10gen.com", "antwerkz.com" ], location : "New York, NY" }
On Tue, Aug 6, 2013 at 5:02 AM, Duchatelle [email protected] wrote:
I made pull request with test case : #503https://github.com/mongodb/morphia/issues/503
— Reply to this email directly or view it on GitHubhttps://github.com/mongodb/morphia/issues/502#issuecomment-22166171 .
fixed in cdcb7fa
Great ! Thanks a lot :)