Return person and phone list

Asked

Viewed 172 times

0

I have an entity called Pessoa. This entity has a phone list of the entity Telefone.

How do I bring the person information and popular the phone list of this person in a select with only hql?


When using the query select u FROM Pessoa, many data are returned. I would like to optimize and bring only the fields código, nome and the telephone list.

The expected result would be equal to this:

inserir a descrição da imagem aqui

Thank you for your attention

  • Ever tried a Join? , then just get the records in select, ex: select u, t.telefone

  • Post the entity code Pessoa and Telefone, please

1 answer

0

You mapped the relationship of Pessoa and Telefone entities?

If they’re mapped with eager Hibernate will do this for you. Through hql you will need to use Join.

Something like:

Select u FROM Pessoa u join Telefone t where u.idPessoa = t.idPessoa

Browser other questions tagged

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