Note that there are some explanatory texts on larger screens.

plurals
  1. POResolving subdocument types with Spring Data and MongoDB
    text
    copied!<p>I'm encountering an error with a Spring Data repository as it attempts to resolve a property expression:</p> <pre><code>public interface ContractRepository extends MongoRepository&lt;Contract,String&gt; { public List&lt;Contract&gt; findByCodeBindings(String binding); } </code></pre> <p>Here's the relevant parts of <code>Contract</code>:</p> <pre><code>@Document(collection="CONTRACTS") public class PersistentContract extends BaseContract { @PersistenceConstructor public PersistentContract(String name, Version version, Code code) { super(name, version, code); } } </code></pre> <p><code>Code</code> is an interface implemented by <code>CodeImpl</code>. It contains a property <code>bindings</code>, which has a getter and setter in <code>Code</code>. So the query's property expression is designed to find those contracts with a nested Code document containing a given binding. So far, so good.</p> <p>However, the problem is an <code>IllegalArgumentException</code> is getting thrown:</p> <pre><code>java.lang.IllegalArgumentException: No property bindings found on my.company.Code! org.springframework.data.mapping.context.AbstractMappingContext.getPersistentPropertyPath(AbstractMappingContext.java:225) </code></pre> <p>Debugging that section of code shows that Spring Data is picking apart the expression and determines there's a property of type <code>Code</code>. However, because <code>Code</code> is an interface, it has no properties listed.</p> <p>Is there a means to hint to Spring Data that either <code>Code</code> has this property or that <code>CodeImpl</code> is the actual type of the <code>code</code> property? I'm surprised that the library doesn't attempt to parse the getters or setters of the interface.</p> <p>This is using spring-data-commons 1.5.1.RELEASE and spring-data-mongodb 1.2.1.RELEASE. </p> <p>Appreciate the help. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload