google-code-export / morphia

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

java.lang.InstantiationException using Query#retrievedField and a simple workaround #376

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version are you using? (Morphia 0.99/Driver 2.7.2/MongoDB 2.0.2)

[SCOPE and ISSUE]
Using the following class hierarchy:

@Entity("mycollection")
public abstract class AbstractParent
{
  ...
}

public class Child extends AbstractParent
{
   private String childField;

   private String anotherChildField;

   ...
}

and constructing a query like this:

Query<AbstractParent> q = ...
q.field("childField").equals("test");

I'm ensuring that only Child instances will be retrieved from the collection. 
Now, I want to retrieve only a subset of the fields of documents retrieved by 
the query, so I simply construct the query like the following one:

Query<AbstractParent> q = ...
q.field("childField").equals("test");
q.retrievedFields(true, "anotherChildField");

I get a java.lang.InstantiationException.

The issue is related to the lack of "className" in the list of fields to 
retrieve.

[WORKAROUND]
Query<AbstractParent> q = ...
q.field("childField").equals("test");
q.retrievedFields(true, "className", "anotherChildField");

I'm wondering if this "behaviour" should be addressed "by design"
enforcing "className" when a query is constructed using retrievedFields.

Thanks.
Luca

Original issue reported on code.google.com by nataluca@gmail.com on 8 Feb 2012 at 11:21

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1810.

Original comment by scotthernandez on 23 Feb 2012 at 6:07

GoogleCodeExporter commented 9 years ago

Original comment by scotthernandez on 23 Feb 2012 at 6:08