title: Spring Data JPA query by discriminator type
body: <p>I've been trying to create a Sping Data JPA repository method that finds an Entity by the discriminator type, among other properties.</p>
  
  <p>I've read the Spring Data JPA documentation and searched here for an answer to this question but couldn't find it.</p>
  
  <p>Take for instance these classes:</p>
  
  <pre><code>public class DynamicAttribute {
  
      String label;
      DynamicType dynamicType;
  }
  
  public abstract class DynamicType {...}
  </code></pre>
  
  <p><code>DynamicType</code> is extended by a few classes.</p>
  
  <p>The method I need in the <code>DynamicAttributeRepository</code> would be something like this:</p>
  
  <pre><code>Optional&lt;DynamicAttribute&gt; findByLabelAndDynamicType(String label, Class&lt;? extends DynamicType&gt; dynamicType);
  </code></pre>
  
  <p>However it doesn't work. If I pass a PersonType.class (PersonType extends DynamicType) as the second parameter and doesn't find any results and says that "PersonType" is not of the expected type "DynamicType".</p>
  
  <p>Could anyone please help?</p>