Embora tenha usado o join fetch no jpql, tive selects a mais. Este foi meu output:
Hibernate:
select
c1_0.id,
c1_0.agencia,
c1_0.banco,
m1_0.conta_id,
m1_0.id,
m1_0.data,
m1_0.descricao,
m1_0.tipo,
m1_0.valor,
c1_0.numero,
c1_0.titular
from
Conta as c1_0
inner join
Movimentacao as m1_0
on m1_0.conta_id = c1_0.id
Hibernate:
select
c1_0.id,
c1_0.agencia,
c1_0.banco,
c1_0.numero,
c1_0.titular
from
Conta as c1_0
where
c1_0.id = ?
Hibernate:
select
c1_0.id,
c1_0.agencia,
c1_0.banco,
c1_0.numero,
c1_0.titular
from
Conta as c1_0
where
c1_0.id = ?
Hibernate:
select
c1_0.id,
c1_0.agencia,
c1_0.banco,
c1_0.numero,
c1_0.titular
from
Conta as c1_0
where
c1_0.id = ?
Hibernate:
select
c1_0.id,
c1_0.agencia,
c1_0.banco,
c1_0.numero,
c1_0.titular
from
Conta as c1_0
where
c1_0.id = ?
Hibernate:
select
c1_0.id,
c1_0.agencia,
c1_0.banco,
c1_0.numero,
c1_0.titular
from
Conta as c1_0
where
c1_0.id = ?
Hibernate:
select
c1_0.id,
c1_0.agencia,
c1_0.banco,
c1_0.numero,
c1_0.titular
from
Conta as c1_0
where
c1_0.id = ?
Hibernate:
select
c1_0.id,
c1_0.agencia,
c1_0.banco,
c1_0.numero,
c1_0.titular
from
Conta as c1_0
where
c1_0.id = ?
Conta: Copper
[br.com.caelum.financas.modelo.Movimentacao@459b6c53]
Conta: Pedro
[br.com.caelum.financas.modelo.Movimentacao@58ec7116, br.com.caelum.financas.modelo.Movimentacao@36fcf6c0, br.com.caelum.financas.modelo.Movimentacao@7026b7ee, br.com.caelum.financas.modelo.Movimentacao@7cb8437d]
Conta: Jose
[br.com.caelum.financas.modelo.Movimentacao@4779aae6, br.com.caelum.financas.modelo.Movimentacao@61ab89b0]
Conta: Ricardo
[br.com.caelum.financas.modelo.Movimentacao@51b01550, br.com.caelum.financas.modelo.Movimentacao@3337d04c, br.com.caelum.financas.modelo.Movimentacao@3cad68df]
Conta: Ana
[br.com.caelum.financas.modelo.Movimentacao@593a6726]
Conta: Murph
[br.com.caelum.financas.modelo.Movimentacao@37637a24, br.com.caelum.financas.modelo.Movimentacao@770beef5]
Conta: Raily
[br.com.caelum.financas.modelo.Movimentacao@38c9e0d6]
Conta: Raily
[br.com.caelum.financas.modelo.Movimentacao@5961e92d]
Usei este JPQL :
select c from Conta c join fetch c.movimentacoes
Este é o código inteiro:
String jpql = "select c from Conta c join fetch c.movimentacoes";
Query query = em.createQuery(jpql);
List<Conta> contas = query.getResultList();
for (Conta conta2 : contas) {
System.out.println();
System.out.println("Conta: " + conta2.getTitular() );
System.out.println(conta2.getMovimentacoes());
}
Não deveria haver apenas um select?