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

Asked

Viewed 239 times

0

Guys, I have the entity Client that extends Pessoa:

@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 make this query, taking the name that is in another table physically in the database, being in the entity Client through inheritance.

1 answer

0


Guys I discovered the problem, the question is that in my entity Person the attribute is mapped as name_person but in the entity is as name.

After the tests worked, Springdata can access attributes inherited from other classes and with different names in the database in relation to the entity itself.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.