HQL
select
new pacote.ReportEntrega(
entrega.id,
entrega.motorista.nome,
entrega.veiculo.descricao,
entrega.dataSaida,
entrega.horaSaida,
entrega.dataRetorno,
entrega.horaRetorno,
entrega.kmInicial,
entrega.kmFinal,
entregaNota.ordem,
entregaNota.chaveEntregaNotas.notaSaida.numero,
entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.razaoSocial,
entregaNota.chaveEntregaNotas.notaSaida.totalNota,
concat(entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.tipoLogradouro.sigla, ' ', entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.logradouro, 'N ', entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.numero),
entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.bairro,
concat(entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.cidade, '/', entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.cidade.uf.sigla),
entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.cep,
substring(entregaNota.observacao,1, 10),
notaSaidaItem.produto.id,
notaSaidaItem.produto.descricao,
sum(notaSaidaItem.quantidade))
from
Entrega entrega
join
entrega.entregaNotas entregaNota
join
entregaNota.chaveEntregaNotas.notaSaida.notaSaidaItens notaSaidaItem
group by
entrega.id,
entrega.motorista.nome,
entrega.veiculo.descricao,
entrega.dataSaida,
entrega.horaSaida,
entrega.dataRetorno,
entrega.horaRetorno,
entrega.kmInicial,
entrega.kmFinal,
entregaNota.ordem,
entregaNota.chaveEntregaNotas.notaSaida.numero,
entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.razaoSocial,
entregaNota.chaveEntregaNotas.notaSaida.totalNota,
concat(entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.tipoLogradouro.sigla, ' ', entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.logradouro, 'N ', entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.numero),
entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.bairro,
concat(entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.cidade, '/', entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.cidade.uf.sigla),
entregaNota.chaveEntregaNotas.notaSaida.notaSaidaCliente.cep,
substring(entregaNota.observacao,1, 10),
notaSaidaItem.produto.id,
notaSaidaItem.produto.descricao
order by
entrega.id,
entregaNota.ordem,
notaSaidaItem.produto.id
Código gerado pelo hibernate
select
entrega0_.id as col_0_0_,
motorista4_.nome as col_1_0_,
veiculo5_.descricao as col_2_0_,
entrega0_.dataSaida as col_3_0_,
entrega0_.horaSaida as col_4_0_,
entrega0_.dataRetorno as col_5_0_,
entrega0_.horaRetorno as col_6_0_,
entrega0_.kmInicial as col_7_0_,
entrega0_.kmFinal as col_8_0_,
entreganot1_.ordem as col_9_0_,
notasaida2_.numero as col_10_0_,
notasaidac8_.razaoSocial as col_11_0_,
notasaida2_.totalNota as col_12_0_,
(tipolograd12_.sigla||' '||notasaidac8_.logradouro||'N '||notasaidac8_.numero) as col_13_0_,
notasaidac8_.bairro as col_14_0_,
(notasaidac8_.cidade_id||'/'||uf25_.sigla) as col_15_0_,
notasaidac8_.cep as col_16_0_,
substring(entreganot1_.observacao,
1,
10) as col_17_0_,
notasaidai3_.produto_id as col_18_0_,
produto28_.descricao as col_19_0_,
sum(notasaidai3_.quantidade) as col_20_0_
from
Entrega entrega0_
inner join
EntregaNotas entreganot1_
on entrega0_.id=entreganot1_.ENTREGA_ID
inner join
NotaSaida notasaida2_
on entreganot1_.NOTASAIDA_ID=notasaida2_.id
inner join
NotaSaidaItens notasaidai3_
on notasaida2_.id=notasaidai3_.NOTASAIDA_ID,
Produto produto28_,
NotaSaidaCliente notasaidac8_,
TipoLogradouro tipolograd12_,
Cidade cidade21_,
UF uf25_,
Motorista motorista4_,
Veiculo veiculo5_
where
notasaidai3_.produto_id=produto28_.id
and notasaida2_.id=notasaidac8_.NOTASAIDA_ID
and notasaidac8_.tipoLogradouro_id=tipolograd12_.id
and notasaidac8_.cidade_id=cidade21_.id
and cidade21_.uf_id=uf25_.id
and entrega0_.motorista_id=motorista4_.id
and entrega0_.veiculo_id=veiculo5_.id
group by
entrega0_.id ,
motorista4_.nome ,
veiculo5_.descricao ,
entrega0_.dataSaida ,
entrega0_.horaSaida ,
entrega0_.dataRetorno ,
entrega0_.horaRetorno ,
entrega0_.kmInicial ,
entrega0_.kmFinal ,
entreganot1_.ordem ,
notasaida2_.numero ,
notasaidac8_.razaoSocial ,
notasaida2_.totalNota ,
(tipolograd12_.sigla||' '||notasaidac8_.logradouro||'N '||notasaidac8_.numero) ,
notasaidac8_.bairro ,
(notasaidac8_.cidade_id||'/'||uf25_.sigla) ,
notasaidac8_.cep ,
substring(entreganot1_.observacao,
1,
10) ,
notasaidai3_.produto_id ,
produto28_.descricao
order by
entrega0_.id,
entreganot1_.ordem,
notasaidai3_.produto_id
Obrigado…