0

I'm using JHipster to generate an app. I have this map: Arquivo has OneToMany relationship with Tabela. And Tabela has OneToMany relationship with Campo.

Arquivo has a property called "versao" (string). I want to do something like:

Page<Campo> findAllByArquivoVersao(String versao, Pageable pageable);

But I'm receiving this error:

Failed to create query for method public abstract org.springframework.data.domain.Page br.com.app.repository.CampoRepository.findAllByArquivoVersao(java.lang.String,org.springframework.data.domain.Pageable)! No property arquivoVersao found for type Campo!

I'm able to do something like findAllByTabelaId...so my mapping is ok. How can I do a query filtering by a property of my parent's parent?

aseolin
  • 1,184
  • 3
  • 17
  • 35

2 Answers2

1

Option 1

Find your Arquivo by Versao from ArquivoRepository, and then call arquivo.getTabelas() and getCampos() for each of them to get the collection of campos you want.

Option 2

Define your own @Query in CampoRepository, like so:

@Query("select c from Campo c where c.tabela.arquivo.versao = :versao")
Page<Campo> findAllByArquivoVersao(@Param("versao") String versao, Pageable pageable);

If you wanted Campos by partial comparison of their versao you can do something like this:

@Query("select c from Campo c where upper(c.tabela.arquivo.versao) like concat('%',upper(:versao),'%')")
Page<Campo> findAllByArquivoVersao(@Param("versao") String versao, Pageable pageable);

Without knowing exactly how you have designed your entities (fetching, nullability, ...) this is as much as I can guess.

I did not test any of this code.

vicpermir
  • 3,544
  • 3
  • 22
  • 34
0

I got it. Spring docs on item 4.4.3 has specified this case:

I have to name my interface method like this: findByTabelaArquivoVersao

aseolin
  • 1,184
  • 3
  • 17
  • 35