google-code-export / morphia

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

Query with Enum Object. #227

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
morphia-0.98 ,driver-2.3,mongo,1.6.4 ,os- ubuntu

I got a entity like this:

   class Book {
      private Type bookType;

      public static enum Type {   // it's necessary to declare the enum to static?
         Paper , Ebook
      }
   }

   After I saved a entity into mongo , I got a record: {book:{ bookType:"Ebook" }}.
   When I query : createQuery().disableValidation().filter("bookType", SpaceType.Ebook) ,
   there won't have any result return,util I query this it using "name()",
   createQuery().disableValidation().filter("bookType", SpaceType.Ebook.name()) ,

   I track down the code ,and found : 
        .morphia.query.FieldCriteria# protected FieldCriteria(QueryImpl<?> query, String field, FilterOperator op, Object value, boolean validateNames, boolean validateTypes) [line 67]
              else
           mappedValue = mapr.toMongoObject(value);

         and value is SpaceType.Ebook -> which turned into { "name" : "support" , "ordinal" : 2} ,
   I don't know whether this will affect the query result.

   So , I have using createQuery().disableValidation().filter("bookType", SpaceType.Ebook.name()) ,which looks a little....

Original issue reported on code.google.com by gogomat...@gmail.com on 16 Feb 2011 at 1:00

GoogleCodeExporter commented 9 years ago

Original comment by scotthernandez on 16 Feb 2011 at 3:48

GoogleCodeExporter commented 9 years ago
I added a simple Test for this in the trunk called "EnumMappingTest". I am not 
able to reproduce the problem. 

gogomatrix: can you please take a look if the problem perists and maybe tweak 
the test to demonstrate the problem?

Original comment by google-a...@codesmell.de on 18 Feb 2011 at 9:54

GoogleCodeExporter commented 9 years ago
Man,I didn't see any EnumMappingTest.java?
Are'you sure u put in there?

Original comment by gogomat...@gmail.com on 1 Mar 2011 at 2:39

GoogleCodeExporter commented 9 years ago
Here is the test: 
http://code.google.com/p/morphia/source/browse/trunk/morphia/src/test/java/com/g
oogle/code/morphia/mapping/EnumMappingTest.java

Original comment by scotthernandez on 1 Mar 2011 at 2:48

GoogleCodeExporter commented 9 years ago
I add a patch for that,pls check it out.
And sorry for opened an new issue,I didn't know.
http://code.google.com/p/morphia/issues/detail?id=235

Original comment by gogomat...@gmail.com on 1 Mar 2011 at 10:16

GoogleCodeExporter commented 9 years ago
Issue 235 has been merged into this issue.

Original comment by google-a...@codesmell.de on 1 Mar 2011 at 11:41

GoogleCodeExporter commented 9 years ago

Original comment by google-a...@codesmell.de on 1 Mar 2011 at 11:41

GoogleCodeExporter commented 9 years ago
patched the mapper to use the parent class instead of the given one for 
instances of an anonymous class where the parent class is an enum.

shouldn´t this behaviour generally be true? (not just for enums)

Original comment by google-a...@codesmell.de on 1 Mar 2011 at 12:00

GoogleCodeExporter commented 9 years ago

Original comment by scotthernandez on 12 Nov 2011 at 7:39