How to access an inherited attribute in an entity with a query in Spring Data

0

I have the Client entity that extends Person:

@Entity
@Table(name = "cliente")
@PrimaryKeyJoinColumn(name="id_pessoa")
@Document(indexName="cliente")
public class Cliente extends Pessoa implements Serializable {

Person has the attribute:

@Column(name = "nm_pessoa")
private String nome;

In my repository I have:

public interface ClienteRepository extends JpaRepository<Cliente,Long> {

//Esse metodo funciona
Page<Cliente> findById(Long id, Pageable pageable);

/*Esse método não retorna nada já que no banco de dados
  os dados estão na outra tabela: pessoa
*/
@Query("SELECT c FROM Cliente c where c.nome like :nome%") //missing order by clause    
Page<Cliente> findByNomeStartingWithOrderByNomeAsc(@Param("nome") String nome, Pageable pageable);

How can I do this query, taking the name that is in another table physically in the database, being in the Client entity through inheritance.

    
asked by anonymous 10.03.2016 / 15:28

1 answer

0

Galera discovered the problem, the issue is that in my Person entity the attribute is mapped as person_name but in the entity is as the name.

After testing has worked, SpringData can access attributes inherited from other classes and with different names in the database relative to the entity itself.

    
15.03.2016 / 13:59