morphia icon indicating copy to clipboard operation
morphia copied to clipboard

Can't inherit HashSet : generic is lost...

Open thomasduchatelle opened this issue 13 years ago • 7 comments

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

thomasduchatelle avatar Aug 05 '13 16:08 thomasduchatelle

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 .

evanchooly avatar Aug 05 '13 17:08 evanchooly

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

thomasduchatelle avatar Aug 05 '13 17:08 thomasduchatelle

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 .

evanchooly avatar Aug 05 '13 17:08 evanchooly

I made pull request with test case : #503

thomasduchatelle avatar Aug 06 '13 09:08 thomasduchatelle

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 .

evanchooly avatar Aug 06 '13 13:08 evanchooly

fixed in cdcb7fa

evanchooly avatar Aug 08 '13 18:08 evanchooly

Great ! Thanks a lot :)

thomasduchatelle avatar Aug 09 '13 08:08 thomasduchatelle