title: SD MongoDB polymorphism in subdocument
body: <p>I just started developing some app in Java with spring-data-mongodb and came across some issue that I haven't been able to solve:</p>
  
  <p>Have a couple of document beans like this:</p>
  
  <pre><code>@Document(collection="myBeanBar")
  public class BarImpl implements Bar {
     String id;
     Foo foo;
     // More fields and methods ...
  }
  
  @Docuemnt
  public class FooImpl implements Foo {
     String id;
     String someField;
     // some more fields and methods ...
  }
  </code></pre>
  
  <p>And I have a repository class with a method that simply invokes a find similar to this:</p>
  
  <pre><code>public List&lt;? extends Bar&gt; findByFooField(final String fieldValue) {
      Query query = Query.query(Criteria.where("foo.someField").is(fieldValue));
      return getMongoOperations().find(query, BarImpl.class);
  }
  </code></pre>
  
  <p>Saving a Bar works just fine, it would save it in mongo along with the "_class" attribute for both Foo and Bar.  However, finding by some attribute in Foo would throw an exception like this:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: No property someField found on test.Foo!
      at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentPropertyPath(AbstractMappingContext.java:225)
      at org.springframework.data.mongodb.core.convert.QueryMapper.getPath(QueryMapper.java:202)
      at org.springframework.data.mongodb.core.convert.QueryMapper.getTargetProperty(QueryMapper.java:190)
      at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:86)
      at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1336)
      at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1322)
      at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:495)
      at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:486)
  </code></pre>
  
  <p>Which, after some digging, makes some sense, since nowhere in the query is the sub-document concrete type being specified, and the Entity Information of Bar says the type of foo is Foo (not FooImpl), which in turn can not have properties cause it is an interface.</p>
  
  <p>My question is:  Is there a way to specify it or work-around this issue without declaring the sub-document type as a concrete type?</p>
  
  <p>I've been googling it for a couple of days and looking at the documentation and API and the source code but I can not find a clear way to do it.  I'd really appreciate your help.</p>
  
  <p>Thank you very much.</p>