title: Spring Data custom query in repository with object inheritance
body: <p>I'm working with Spring MVC + Data + Security and I'm having trouble with Spring Data. I have 3 entities (with different properties between them) which extend to another entity, and I'm trying to do a query from one of them based on the parent. </p>
  
  <p>Here the code:</p>
  
  <p><strong>Perfil</strong> <em>(means Profile, but when I tried to use profile I got issues)</em> is the parent or super class of the other <strong>3 classes</strong></p>
  
  <pre><code>@Entity
  @Inheritance(strategy = InheritanceType.JOINED)
  public class Perfil {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;
  
      ...
  </code></pre>
  
  <p>And this is <strong>Person</strong>, which extends from <strong>Perfil</strong></p>
  
  <pre><code>@Entity
  @PrimaryKeyJoinColumn(name = "perfil_id")
  public class Person extends Perfil {
  
      private String firstName;
  
      private String lastName;
  
      private Gender gender;
  </code></pre>
  
  <p>And I have the <strong>PersonRepository</strong>. It has a method where I'm trying to find <strong>Person</strong> using the <strong>Perfil ID</strong></p>
  
  <pre><code>@Repository
  public interface PersonRepository extends CrudRepository&lt;Person, Integer&gt; {
      @Query("SELECT p FROM Person p WHERE p.perfil_id=?1")
      Person findByProfileID(Integer id);
  }
  </code></pre>
  
  <p>And I get this error</p>
  
  <pre><code>Caused by: org.hibernate.QueryException: could not resolve property: perfil_id of: com.giulianok.person.Person [SELECT p FROM com.giulianok.person.Person p WHERE p.perfil_id=?1]
      at org.hibernate.QueryException.generateQueryException(QueryException.java:137) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:120) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:234) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:131) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:93) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1836) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:328) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
      ... 96 common frames omitted
  </code></pre>
  
  <p>What I understand is Spring can't find "perfil_id" inside of Person, that make sense because I don't have that property, but at the end, when I take a look at the Database, I see the column "perfil_id"</p>
  
  <p>The thing is, <strong>how can I make the query based on Object inheritance?</strong></p>