google-code-export / morphia

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

Cannot search using hasAnyOf when using a composite id and noClassNameStore=true #387

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, 

I have an entity annotated with @Entity where noClassNameStored is set 
to true and the id of the entity is a composite id. When persisting 
the entity no class name is stored in Mongo neither for the entity or 
for the ID object. But when I search using the following query 

List<MyCompositeId> ids = ... 
List<MyEntity> entityList =                 
find(createQuery().field("_id").hasAnyOf(ids)).asList(); 

Morphia inserts the class name of the composite id in the query and 
thus no entities are found. If I manually cut and paste the query and 
remove the className from the query it's successful. I assume that 
this is a bug? 

If I inspect "createQuery().field("_id").hasAnyOf(ids)" in the debugger the 
query looks like this:
{ "_id" : { "$in" : [ { "className" : "com.x.y.MyCompositeId" , "x" : "x" , "y" 
: "y" } , { "className" : "com.x.y.MyCompositeId" , "x" : "x" , "y" : "z"}]}}

If I manually remove the className attribute from the query and execute in the 
the mongodb console it finds the entities.

My classes looks resembles this:

@Entity(noClassNameStored=true)
public class MyEntity {
   @Id
   private MyCompositeId myId;

   public MyEntity(String x, String y) {
    this.myId = new MyCompositeId(x, y);
   }

   ...
}

public class MyCompositeId {
   private String x;
   private String y;

   public MyCompositeId(String x, String y) {
        this.x = x;
    this.y = y;
   }
}

Original issue reported on code.google.com by johan.ha...@gmail.com on 8 Mar 2012 at 7:44

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Actually I noticed that it doesn't work even when I use 
noClassNameStored=false. No className attribtue seems to be generated for the 
composite id.

Original comment by johan.ha...@gmail.com on 8 Mar 2012 at 10:19

GoogleCodeExporter commented 9 years ago
So, is there any activity on this?
I just reproduced it on plain get(Class<T> clazz, V id) where id is composite 
key.

Original comment by sergey.palyanov on 22 Mar 2013 at 4:14