E ai, blz?
Descobri uma coisa muito boa aqui que pode interessar àqueles que mexem com proxies, fetch, Hibernate.initialize(…) e q estão aprendendo a colocar maior performance no hibernate.
Eu tava verificando aqui, através de um programa que verifica os pacotes trafegando na rede e fiquei monitorando uma query que eu tava fazendo.
Primeiramente eu fiz o código da seguinte maneira:
query = "from User u";
query += " where u.login = '" + login + "'";
query += " and u.password = '" + passCrypt + "'";
.
.
.
Hibernate.initialize(user.getTemplate());
Hibernate.initialize(user.getUserStatus());
Hibernate.initialize(user.getUfRg());
o código acima gerou cerca de 18k trafegando na rede e gerou
os seguintes códigos SQL:
1110454643671|31|2|statement|select distinct user0_.cpf as cpf,
user0_.rg as rg, user0_.uf_rg as uf_rg, user0_.nome as nome,
user0_.login as login, user0_.senha as senha, user0_.email as email,
user0_.cargo as cargo, user0_.id_perfil as id_perfil,
user0_.id_usuario_status as id_usua10_, user0_.dt_inclusao as dt_incl11_,
user0_.dt_exclusao as dt_excl12_, user0_.primeiro_acesso as primeir13_
from usuario user0_, perfil template1_, empresa company2_, empresa
company3_ where (user0_.login='fcompaq' )
and(user0_.senha='01ux7/b5aiw=' )and(user0_.id_usuario_status='1'
)and(company2_.id_empresa_status in('A' , 'S' , 'P') and
user0_.id_perfil=template1_.id_perfil and
template1_.cnpj=company2_.cnpj)and(((company2_.cnpj_pai is null and
user0_.id_perfil=template1_.id_perfil and
template1_.cnpj=company2_.cnpj))or(((company2_.cnpj_pai is not null
and user0_.id_perfil=template1_.id_perfil and
template1_.cnpj=company2_.cnpj))and((company3_.id_empresa_status
in('A' , 'S' , 'P') and user0_.id_perfil=template1_.id_perfil and
template1_.cnpj=company2_.cnpj and
company2_.cnpj_pai=company3_.cnpj))))|select distinct user0_.cpf as cpf,
user0_.rg as rg, user0_.uf_rg as uf_rg, user0_.nome as nome,
user0_.login as login, user0_.senha as senha, user0_.email as email,
user0_.cargo as cargo, user0_.id_perfil as id_perfil,
user0_.id_usuario_status as id_usua10_, user0_.dt_inclusao as dt_incl11_,
user0_.dt_exclusao as dt_excl12_, user0_.primeiro_acesso as primeir13_
from usuario user0_, perfil template1_, empresa company2_, empresa
company3_ where (user0_.login='fcompaq'
)and(user0_.senha='01ux7/b5aiw=' )and(user0_.id_usuario_status='1' )
and(company2_.id_empresa_status in('A' , 'S' , 'P') and
user0_.id_perfil=template1_.id_perfil and
template1_.cnpj=company2_.cnpj)and(((company2_.cnpj_pai is null and
user0_.id_perfil=template1_.id_perfil and
template1_.cnpj=company2_.cnpj))or(((company2_.cnpj_pai is not null
and user0_.id_perfil=template1_.id_perfil and
template1_.cnpj=company2_.cnpj))and((company3_.id_empresa_status
in('A' , 'S' , 'P') and user0_.id_perfil=template1_.id_perfil and
template1_.cnpj=company2_.cnpj and
company2_.cnpj_pai=company3_.cnpj))))
1110454643703|-1||resultset|select distinct user0_.cpf as cpf, user0_.rg as rg, user0_.uf_rg as uf_rg, user0_.nome
as nome, user0_.login as login, user0_.senha as senha, user0_.email as email, user0_.cargo as cargo, user0_.id_perfil
as id_perfil, user0_.id_usuario_status as id_usua10_, user0_.dt_inclusao as dt_incl11_, user0_.dt_exclusao as dt_excl12_,
user0_.primeiro_acesso as primeir13_ from usuario user0_, perfil template1_, empresa company2_, empresa company3_ where
(user0_.login='fcompaq' )and(user0_.senha='01ux7/b5aiw=' )and(user0_.id_usuario_status='1' )and(company2_.id_empresa_status
in('A' , 'S' , 'P') and user0_.id_perfil=template1_.id_perfil
and template1_.cnpj=company2_.cnpj)and(((company2_.cnpj_pai is null and user0_.id_perfil=template1_.id_perfil and template1_.
cnpj=company2_.cnpj))or(((company2_.cnpj_pai is not null and user0_.id_perfil=template1_.id_perfil and template1_.cnpj=company2_.cnpj))and(
(company3_.id_empresa_status in('A' , 'S' , 'P') and user0_.id_perfil=template1_.id_perfil and template1_.cnpj=company2_.cnpj and company2_.
cnpj_pai=company3_.cnpj))))|cargo = PROGRAMADOR, cpf = 33807840281, email = bogas@hst.com.br, id_usua10_ = 1, login = fcompaq, nome = US.
COMPAQ FILIAL, primeir13_ = 1, rg = 54625842, senha = 01ux7/b5aiw=, uf_rg = 30
1110454643812|94|2|statement|select template0_.id_perfil as id_perfil4_, template0_.nome as nome4_, template0_.ds_perfil as
ds_perfil4_, template0_.pm_perfil as pm_perfil4_, template0_.cnpj as cnpj4_, template0_.id_perfil_pai as id_perfi6_4_, company1_.cnpj as
cnpj0_, company1_.id_indicador as id_indic2_0_, company1_.id_empresa_status as id_empre3_0_, company1_.id_atividade_tipo as id_ativi4_0_,
company1_.dt_pedido_acesso as dt_pedid5_0_,
company1_.dt_manutencao as dt_manut6_0_, company1_.nome as
nome0_, company1_.razao_social as razao_so8_0_,
company1_.logradouro as logradouro0_, company1_.numero as
numero0_, company1_.complemento as complem11_0_, company1_.bairro as bairro0_, company1_.id_cidade as id_cidade0_, company1_.cep as
cep0_, company1_.ddd_telefone as ddd_tel15_0_, company1_.telefone as telefone0_, company1_.ddd_fax as ddd_fax0_, company1_.fax as fax0_,
company1_.cpf_contato as cpf_con19_0_, company1_.nr_banco as nr_banco0_, company1_.agencia as agencia0_, company1_.nr_conta as nr_conta0_,
company1_.fg_conta as fg_conta0_, company1_.cnpj_ted as cnpj_ted0_, company1_.cnpj_pai as cnpj_pai0_, company1_.fg_manutencao as fg_manu26_0_,
company1_.tp_conta as tp_conta0_, user2_.cpf as cpf1_, user2_.rg as rg1_, user2_.uf_rg
as uf_rg1_, user2_.nome as nome1_, user2_.login as login1_, user2_.senha as senha1_, user2_.email as email1_, user2_.cargo as cargo1_,
user2_.id_perfil as id_perfil1_, user2_.id_usuario_status as id_usua10_1_, user2_.dt_inclusao as dt_incl11_1_, user2_.dt_exclusao as dt_excl12_1_,
user2_.primeiro_acesso as primeir13_1_, state3_.id_estado as id_estado2_, state3_.no_estado as no_estado2_, state3_.id_pais as id_pais2_,
transactio4_.cnpj as cnpj3_, transactio4_.fg_transacao_taxa as fg_trans2_3_, transactio4_.valor as valor3_, transactio4_.porcentagem as
porcenta4_3_, transactio4_.limite as limite3_ from perfil template0_, empresa company1_, usuario user2_, estado state3_, transacao_taxa
transactio4_ where template0_.id_perfil=? and template0_.cnpj=company1_.cnpj(+) and company1_.cpf_contato=user2_.cpf(+)
and user2_.uf_rg=state3_.id_estado(+) and company1_.cnpj=transactio4_.cnpj(+)|select template0_.id_perfil as id_perfil4_, template0_.nome
as nome4_, template0_.ds_perfil as ds_perfil4_, template0_.pm_perfil as pm_perfil4_, template0_.cnpj as cnpj4_, template0_.id_perfil_pai
as id_perfi6_4_, company1_.cnpj as cnpj0_, company1_.id_indicador as id_indic2_0_, company1_.id_empresa_status as id_empre3_0_,
company1_.id_atividade_tipo as id_ativi4_0_, company1_.dt_pedido_acesso as dt_pedid5_0_, company1_.dt_manutencao as dt_manut6_0_,
company1_.nome as nome0_, company1_.razao_social as razao_so8_0_, company1_.logradouro as logradouro0_, company1_.numero as numero0_,
company1_.complemento as complem11_0_, company1_.bairro as bairro0_, company1_.id_cidade as id_cidade0_, company1_.cep as cep0_,
company1_.ddd_telefone as ddd_tel15_0_, company1_.telefone as telefone0_, company1_.ddd_fax as ddd_fax0_, company1_.fax as fax0_,
company1_.cpf_contato as cpf_con19_0_, company1_.nr_banco as nr_banco0_, company1_.agencia as agencia0_, company1_.nr_conta as
nr_conta0_, company1_.fg_conta as fg_conta0_, company1_.cnpj_ted as cnpj_ted0_, company1_.cnpj_pai as cnpj_pai0_, company1_.fg_manutencao
as fg_manu26_0_, company1_.tp_conta as tp_conta0_, user2_.cpf as cpf1_, user2_.rg as rg1_, user2_.uf_rg as uf_rg1_, user2_.nome as nome1_,
user2_.login as login1_, user2_.senha as senha1_, user2_.email as email1_, user2_.cargo as cargo1_, user2_.id_perfil as id_perfil1_,
user2_.id_usuario_status as id_usua10_1_, user2_.dt_inclusao as dt_incl11_1_, user2_.dt_exclusao as dt_excl12_1_, user2_.primeiro_acesso as
primeir13_1_,
state3_.id_estado as id_estado2_, state3_.no_estado as no_estado2_, state3_.id_pais as id_pais2_, transactio4_.cnpj as cnpj3_,
transactio4_.fg_transacao_taxa as fg_trans2_3_, transactio4_.valor as valor3_, transactio4_.porcentagem as porcenta4_3_, transactio4_.limite
as limite3_ from perfil template0_, empresa company1_, usuario user2_, estado state3_, transacao_taxa transactio4_ where template0_.id_perfil=18
and template0_.cnpj=company1_.cnpj(+) and company1_.cpf_contato=user2_.cpf(+) and user2_.uf_rg=state3_.id_estado(+)
and company1_.cnpj=transactio4_.cnpj(+)
1110454643828|-1||resultset|select template0_.id_perfil as id_perfil4_, template0_.nome as nome4_, template0_.ds_perfil as ds_perfil4_,
template0_.pm_perfil as pm_perfil4_, template0_.cnpj as cnpj4_, template0_.id_perfil_pai as id_perfi6_4_, company1_.cnpj as cnpj0_, company1_.
id_indicador as id_indic2_0_, company1_.id_empresa_status as id_empre3_0_, company1_.id_atividade_tipo as id_ativi4_0_, company1_.dt_pedido_acesso
as dt_pedid5_0_, company1_.dt_manutencao as dt_manut6_0_, company1_.nome as nome0_, company1_.razao_social as razao_so8_0_, company1_.
logradouro
as logradouro0_, company1_.numero as numero0_, company1_.complemento as complem11_0_, company1_.bairro as bairro0_, company1_.id_cidade as
id_cidade0_,
company1_.cep as cep0_, company1_.ddd_telefone as ddd_tel15_0_, company1_.telefone as telefone0_, company1_.ddd_fax as ddd_fax0_, company1_.fax
as fax0_, company1_.cpf_contato as cpf_con19_0_, company1_.nr_banco as nr_banco0_, company1_.agencia as agencia0_, company1_.nr_conta as nr_conta0_,
company1_.fg_conta as fg_conta0_, company1_.cnpj_ted as cnpj_ted0_, company1_.cnpj_pai as cnpj_pai0_, company1_.fg_manutencao as fg_manu26_0_,
company1_.tp_conta as tp_conta0_, user2_.cpf as cpf1_,
user2_.rg as rg1_, user2_.uf_rg as uf_rg1_, user2_.nome as nome1_, user2_.login as login1_, user2_.senha as senha1_, user2_.email as email1_,
user2_.cargo as cargo1_, user2_.id_perfil as id_perfil1_, user2_.id_usuario_status as id_usua10_1_, user2_.dt_inclusao as dt_incl11_1_,
user2_.dt_exclusao as dt_excl12_1_, user2_.primeiro_acesso as primeir13_1_, state3_.id_estado as id_estado2_, state3_.no_estado as
no_estado2_, state3_.id_pais as id_pais2_, transactio4_.cnpj as cnpj3_, transactio4_.fg_transacao_taxa as fg_trans2_3_, transactio4_.valor
as valor3_, transactio4_.porcentagem as porcenta4_3_, transactio4_.limite as limite3_ from perfil template0_, empresa company1_,
usuario user2_, estado state3_, transacao_taxa transactio4_ where template0_.id_perfil=18 and template0_.cnpj=company1_.cnpj(+) and
company1_.cpf_contato=user2_.cpf(+) and user2_.uf_rg=state3_.id_estado(+) and company1_.cnpj=transactio4_.cnpj(+)|agencia0_ = 0001,
bairro0_ = JARDIM DO TREVO, cep0_ = 12910000, cnpj0_ = 16361234000102, cnpj3_ = 16361234000102, cnpj4_ = 16361234000102, cnpj_pai0_ = 91971872000152,
cnpj_ted0_ = 16361234000102, complem11_0_ = COMPLEM., cpf1_ = 33807840281, cpf_con19_0_ = 33807840281, ddd_fax0_ = 19, ddd_tel15_0_ = 19,
ds_perfil4_ = LIBERA ACESSO AOS USUARIOS DO PONTO DE EMBARQUE, fax0_ = 38672222, fg_conta0_ = 0, fg_manu26_0_ = 0, fg_trans2_3_ = 0, id_ativi4_0_ = 2,
id_empre3_0_ = A, id_estado2_ = 30, id_indic2_0_ = E, id_pais2_ = 8, logradouro0_ = R.TAQUARAL, no_estado2_ = RS, nome0_ = COMPAQ FILIAL,
nome4_ = MASTER EMBARQUE, nr_banco0_ = 749, nr_conta0_ = 0000000001, numero0_ = 20, pm_perfil4_ =
C0A0F800F0D8F6C0FC00F8000000000000000000000000000000000000000000, razao_so8_0_ = COMPAQ FILIAL, telefone0_ = 38672222, tp_conta0_ = 0
1110454643968|62|2|statement|select routes0_.id_rota as id_rota__, routes0_.cnpj as cnpj__, routes0_.id_rota as id_rota0_, routes0_.no_rota as
no_rota0_
routes0_.id_cidade_origem as id_cidad3_0_, routes0_.id_cidade_destino as id_cidad4_0_, routes0_.id_rota_status as id_rota_5_0_, routes0_.cnpj
as cnpj0_,
routes0_.id_categoria_veiculo as id_categ7_0_ from rota routes0_ where routes0_.cnpj=?|select routes0_.id_rota as id_rota__, routes0_.cnpj
as cnpj__, routes0_.id_rota as id_rota0_, routes0_.no_rota as no_rota0_, routes0_.id_cidade_origem as id_cidad3_0_, routes0_.id_cidade_destino
as id_cidad4_0_, routes0_.id_rota_status as id_rota_5_0_, routes0_.cnpj as cnpj0_, routes0_.id_categoria_veiculo as id_categ7_0_ from rota
routes0_ where routes0_.cnpj='16361234000102'
1110454644015|31|2|statement|select monthlyfee0_.id_mensalidade as id_mensa1___, monthlyfee0_.cnpj as cnpj__, monthlyfee0_.id_mensalidade as
id_mensa1_1_,
monthlyfee0_.cnpj as cnpj1_, monthlyfee0_.id_dia_vencimento as id_dia_v3_1_, monthlyfee0_.valor as valor1_, monthlyfee0_.id_mensalidade_status
as id_mensa5_1_, monthlyfee0_.id_empresa_status as id_empre6_1_, monthlyfee0_.dt_pagamento as dt_pagam7_1_, monthlyfee0_.dt_vencimento as
dt_venci8_1_, monthlyfee0_.tp_cobranca as tp_cobra9_1_, monthlyfee0_.agencia as agencia1_, monthlyfee0_.cd_cliente as cd_cliente1_,
monthlyfee0_.dt_geracao as dt_geracao1_, companysta1_.id_empresa_status as id_empre1_0_, companysta1_.ds_empresa_status as ds_empre2_0_
from
mensalidade monthlyfee0_, empresa_status companysta1_ where monthlyfee0_.cnpj=? and monthlyfee0_.id_empresa_status=companysta1_.id_empresa_status(+)|
select monthlyfee0_.id_mensalidade as id_mensa1___, monthlyfee0_.cnpj as cnpj__, monthlyfee0_.id_mensalidade as id_mensa1_1_, monthlyfee0_.cnpj as
cnpj1_, monthlyfee0_.id_dia_vencimento as id_dia_v3_1_, monthlyfee0_.valor as valor1_, monthlyfee0_.id_mensalidade_status as id_mensa5_1_,
monthlyfee0_.id_empresa_status as id_empre6_1_, monthlyfee0_.dt_pagamento as dt_pagam7_1_,
monthlyfee0_.dt_vencimento as dt_venci8_1_, monthlyfee0_.tp_cobranca as tp_cobra9_1_, monthlyfee0_.agencia as agencia1_,
monthlyfee0_.cd_cliente
as cd_cliente1_, monthlyfee0_.dt_geracao as dt_geracao1_, companysta1_.id_empresa_status as id_empre1_0_, companysta1_.ds_empresa_status
as ds_empre2_0_ from mensalidade monthlyfee0_, empresa_status companysta1_ where monthlyfee0_.cnpj='16361234000102' and
monthlyfee0_.id_empresa_status=companysta1_.id_empresa_status(+)
1110454644078|47|2|statement|select templates0_.id_perfil as id_perfil__, templates0_.cnpj as cnpj__, templates0_.id_perfil as id_perfil1_,
templates0_.nome as nome1_, templates0_.ds_perfil as ds_perfil1_, templates0_.pm_perfil as pm_perfil1_, templates0_.cnpj as cnpj1_,
templates0_.id_perfil_pai as id_perfi6_1_, template1_.id_perfil as id_perfil0_, template1_.nome as nome0_, template1_.ds_perfil as
ds_perfil0_, template1_.pm_perfil as pm_perfil0_, template1_.cnpj as cnpj0_, template1_.id_perfil_pai as id_perfi6_0_ from perfil
templates0_, perfil template1_ where templates0_.cnpj=? and templates0_.id_perfil_pai=template1_.id_perfil(+)|select templates0_.id_perfil
as id_perfil__, templates0_.cnpj as cnpj__, templates0_.id_perfil as id_perfil1_, templates0_.nome as nome1_, templates0_.ds_perfil as
ds_perfil1_, templates0_.pm_perfil as pm_perfil1_, templates0_.cnpj as cnpj1_, templates0_.id_perfil_pai as id_perfi6_1_, template1_.id_perfil
as id_perfil0_, template1_.nome as nome0_, template1_.ds_perfil as ds_perfil0_, template1_.pm_perfil as pm_perfil0_, template1_.cnpj
as cnpj0_, template1_.id_perfil_pai as id_perfi6_0_ from perfil templates0_, perfil template1_ where templates0_.cnpj='16361234000102'
and templates0_.id_perfil_pai=template1_.id_perfil(+)
1110454644078|-1||resultset|select templates0_.id_perfil as id_perfil__, templates0_.cnpj as cnpj__, templates0_.id_perfil as id_perfil1_,
templates0_.nome as nome1_, templates0_.ds_perfil as ds_perfil1_, templates0_.pm_perfil as pm_perfil1_, templates0_.cnpj as cnpj1_,
templates0_.id_perfil_pai as id_perfi6_1_, template1_.id_perfil as id_perfil0_, template1_.nome as nome0_, template1_.ds_perfil as ds_perfil0_,
template1_.pm_perfil as pm_perfil0_, template1_.cnpj as cnpj0_, template1_.id_perfil_pai as id_perfi6_0_ from perfil templates0_, perfil
template1_ where templates0_.cnpj='16361234000102' and templates0_.id_perfil_pai=template1_.id_perfil(+)|cnpj0_ = 01000786000100, cnpj__
= 16361234000102, ds_perfil0_ = I O RESPONSAVEL PELAS EMPRESAS FILIAIS. , nome0_ = MASTER EMBARQUE, pm_perfil0_ =
C0A0F800F0D8F6C0FC00F8000080000000000000000000000000000000000000
1110454644093|-1||resultset|select templates0_.id_perfil as id_perfil__, templates0_.cnpj as cnpj__, templates0_.id_perfil as id_perfil1_,
templates0_.nome as nome1_, templates0_.ds_perfil as ds_perfil1_, templates0_.pm_perfil as pm_perfil1_, templates0_.cnpj as cnpj1_,
templates0_.id_perfil_pai as id_perfi6_1_, template1_.id_perfil as id_perfil0_, template1_.nome as nome0_, template1_.ds_perfil as ds_perfil0_,
template1_.pm_perfil as pm_perfil0_, template1_.cnpj as cnpj0_, template1_.id_perfil_pai as id_perfi6_0_ from perfil templates0_, perfil
template1_ where templates0_.cnpj='16361234000102' and templates0_.id_perfil_pai=template1_.id_perfil(+)|cnpj0_ = 01000786000100,
cnpj1_ = 16361234000102, cnpj__ = 16361234000102, ds_perfil0_ = OPERA AS FUNCOES BASICAS DO SISTEMA, ds_perfil1_ = OPERA AS FUNCOES
BASICAS DO SISTEMA, nome0_ = OPERADOR, nome1_ = OPERADOR, pm_perfil0_ = 0080800000D8A280300000000000000000000000000000000000000000000000,
pm_perfil1_ = 0080800000D8A280300000000000000000000000000000000000000000000000
1110454644093|-1||resultset|select templates0_.id_perfil as id_perfil__, templates0_.cnpj as cnpj__, templates0_.id_perfil as id_perfil1_,
templates0_.nome as nome1_, templates0_.ds_perfil as ds_perfil1_, templates0_.pm_perfil as pm_perfil1_, templates0_.cnpj as cnpj1_,
templates0_.id_perfil_pai as id_perfi6_1_, template1_.id_perfil as id_perfil0_, template1_.nome as nome0_, template1_.ds_perfil as
ds_perfil0_, template1_.pm_perfil as pm_perfil0_, template1_.cnpj as cnpj0_, template1_.id_perfil_pai as id_perfi6_0_ from perfil
templates0_, perfil template1_ where templates0_.cnpj='16361234000102' and templates0_.id_perfil_pai=template1_.id_perfil(+)|
cnpj0_ = 01000786000100, cnpj1_ = 16361234000102, cnpj__ = 16361234000102, ds_perfil0_ = OPERA AS FUNCOES BASICAS E FINANCEIRAS DO
SISTEMA, ds_perfil1_ = OPERA AS FUNCOES BASICAS E FINANCEIRAS DO SISTEMA, nome0_ = FINANCEIRO, nome1_ = FINANCEIRO, pm_perfil0_ =
C080800000D8F6C03C0000000000000000000000000000000000000000000000, pm_perfil1_ = C080800000D8F6C03C0000000000000000000000000000000000000000000000
1110454644109|-1||resultset|select templates0_.id_perfil as id_perfil__, templates0_.cnpj as cnpj__, templates0_.id_perfil as id_perfil1_,
templates0_.nome as nome1_, templates0_.ds_perfil as ds_perfil1_, templates0_.pm_perfil as pm_perfil1_, templates0_.cnpj as cnpj1_,
templates0_.id_perfil_pai as id_perfi6_1_, template1_.id_perfil as id_perfil0_, template1_.nome as nome0_, template1_.ds_perfil as
ds_perfil0_, template1_.pm_perfil as pm_perfil0_, template1_.cnpj as cnpj0_, template1_.id_perfil_pai as id_perfi6_0_ from perfil
templates0_, perfil template1_ where templates0_.cnpj='16361234000102' and templates0_.id_perfil_pai=template1_.id_perfil(+)|cnpj1_
= 16361234000102, cnpj__ = 16361234000102, ds_perfil1_ = TESTE, nome1_ = TESTE, pm_perfil1_ =
C0A0F800F0D8F6C0FC00F0000000000000000000000000000000000000000000
1110454644109|-1||resultset|select templates0_.id_perfil as id_perfil__, templates0_.cnpj as cnpj__, templates0_.id_perfil as id_perfil1_,
templates0_.nome as nome1_, templates0_.ds_perfil as ds_perfil1_, templates0_.pm_perfil as pm_perfil1_, templates0_.cnpj as cnpj1_,
templates0_.id_perfil_pai as id_perfi6_1_, template1_.id_perfil as id_perfil0_, template1_.nome as nome0_, template1_.ds_perfil as
ds_perfil0_, template1_.pm_perfil as pm_perfil0_, template1_.cnpj as cnpj0_, template1_.id_perfil_pai as id_perfi6_0_ from perfil
templates0_, perfil template1_ where templates0_.cnpj='16361234000102' and templates0_.id_perfil_pai=template1_.id_perfil(+)|cnpj1_
= 16361234000102, cnpj__ = 16361234000102, ds_perfil1_ = TESTE, nome1_ = TANIA, pm_perfil1_ =
C0A0F800F0D8F6C0FC00F0000000000000000000000000000000000000000000
1110454644156|16|2|statement|select userstatus0_.id_usuario_status as id_usuar1_0_, userstatus0_.ds_usuario_status as ds_usuar2_0_ from
usuario_status userstatus0_ where userstatus0_.id_usuario_status=?|select userstatus0_.id_usuario_status as id_usuar1_0_, userstatus0_.
ds_usuario_status as ds_usuar2_0_ from usuario_status userstatus0_ where userstatus0_.id_usuario_status=1
1110454644156|-1||resultset|select userstatus0_.id_usuario_status as id_usuar1_0_, userstatus0_.ds_usuario_status as ds_usuar2_0_ from
usuario_status userstatus0_ where userstatus0_.id_usuario_status=1|ds_usuar2_0_ = HABILITADO
Depois alterei o código pra executar da seguinte maneira:
query = "from User u";
query += " inner join fetch u.template";
query += " inner join fetch u.userStatus";
query += " left join fetch u.ufRg";
query += " where u.login = '" + login + "'";
query += " and u.password = '" + passCrypt + "'";
Este último código gerou apenas 4k de tráfego na rede e gerou
os SQLs:
1110464221671|46|1|statement|select distinct user0_.cpf as cpf0_, state3_.id_estado as id_estado1_, userstatus2_.id_usuario_status as
id_usuar1_2_, template1_.id_perfil as id_perfil3_, user0_.rg as rg0_, user0_.uf_rg as uf_rg0_, user0_.nome as nome0_, user0_.login as login0_, user0_.
senha as senha0_, user0_.email as email0_, user0_.cargo as cargo0_, user0_.id_perfil as id_perfil0_,
user0_.id_usuario_status as id_usua10_0_, user0_.dt_inclusao as dt_incl11_0_, user0_.dt_exclusao as dt_excl12_0_, user0_.primeiro_acesso as
primeir13_0_, state3_.no_estado as no_estado1_, state3_.id_pais as id_pais1_, userstatus2_.ds_usuario_status as ds_usuar2_2_, template1_.nome
as nome3_, template1_.ds_perfil as ds_perfil3_, template1_.pm_perfil as pm_perfil3_,
template1_.cnpj as cnpj3_, template1_.id_perfil_pai as id_perfi6_3_ from usuario user0_, perfil template1_, usuario_status userstatus2_,
estado state3_, empresa company4_, empresa company5_ where user0_.id_perfil=template1_.id_perfil and user0_.id_usuario_status=userstatus2_.
id_usuario_status
and user0_.uf_rg=state3_.id_estado(+) and ((user0_.login='fcompaq' )and(user0_.senha='01ux7/b5aiw=' )and(userstatus2_.id_usuario_status='1'
and user0_.id_usuario_status=userstatus2_.id_usuario_status)and(company4_.id_empresa_status in('A' , 'S' , 'P') and user0_.id_perfil=template1_.
id_perfil and template1_.cnpj=company4_.cnpj)and(((company4_.cnpj_pai is null and user0_.id_perfil=template1_.id_perfil
and template1_.cnpj=company4_.cnpj))or(((company4_.cnpj_pai is not null and user0_.id_perfil=template1_.id_perfil and template1_.cnpj=company4_.cnpj))
and((company5_.id_empresa_status in('A' , 'S' , 'P') and user0_.id_perfil=template1_.id_perfil and template1_.cnpj=company4_.cnpj and company4_.
cnpj_pai=company5_.cnpj)))))|select distinct user0_.cpf as cpf0_,
state3_.id_estado as id_estado1_, userstatus2_.id_usuario_status as id_usuar1_2_, template1_.id_perfil as id_perfil3_, user0_.rg as rg0_,
user0_.uf_rg as uf_rg0_, user0_.nome as nome0_, user0_.login as login0_, user0_.senha as senha0_, user0_.email as email0_, user0_.cargo as cargo0_,
user0_.id_perfil as id_perfil0_, user0_.id_usuario_status as id_usua10_0_, user0_.dt_inclusao as dt_incl11_0_,
user0_.dt_exclusao as dt_excl12_0_, user0_.primeiro_acesso as primeir13_0_, state3_.no_estado as no_estado1_, state3_.id_pais as id_pais1_,
userstatus2_.ds_usuario_status as ds_usuar2_2_, template1_.nome as nome3_, template1_.ds_perfil as ds_perfil3_, template1_.pm_perfil as pm_perfil3_,
template1_.cnpj as cnpj3_, template1_.id_perfil_pai as id_perfi6_3_ from usuario user0_, perfil template1_, usuario_status userstatus2_, estado state3_,
empresa company4_, empresa company5_ where user0_.id_perfil=template1_.id_perfil and user0_.id_usuario_status=userstatus2_.id_usuario_status and
user0_.uf_rg=state3_.id_estado(+) and ((user0_.login='fcompaq' )and(user0_.senha='01ux7/b5aiw=' )and(userstatus2_.id_usuario_status='1' and user0_.
id_usuario_status=userstatus2_.id_usuario_status)and(company4_.id_empresa_status in('A' , 'S' , 'P') and user0_.id_perfil=template1_.id_perfil and
template1_.cnpj=company4_.cnpj)and(((company4_.cnpj_pai is null and user0_.id_perfil=template1_.id_perfil
and template1_.cnpj=company4_.cnpj))or(((company4_.cnpj_pai is not null and user0_.id_perfil=template1_.id_perfil and template1_.cnpj=company4_.
cnpj))and((company5_.id_empresa_status in('A' , 'S' , 'P') and user0_.id_perfil=template1_.id_perfil and template1_.cnpj=company4_.cnpj and company4_.
cnpj_pai=company5_.cnpj)))))
1110464221781|-1||resultset|select distinct user0_.cpf as cpf0_, state3_.id_estado as id_estado1_, userstatus2_.id_usuario_status as id_usuar1_2_,
template1_.id_perfil as id_perfil3_,
user0_.rg as rg0_, user0_.uf_rg as uf_rg0_, user0_.nome as nome0_, user0_.login as login0_, user0_.senha as senha0_, user0_.email as email0_,
user0_.cargo as cargo0_, user0_.id_perfil as id_perfil0_, user0_.id_usuario_status as id_usua10_0_, user0_.dt_inclusao as dt_incl11_0_, user0_.
dt_exclusao as dt_excl12_0_, user0_.primeiro_acesso as primeir13_0_, state3_.no_estado as no_estado1_,
state3_.id_pais as id_pais1_, userstatus2_.ds_usuario_status as ds_usuar2_2_, template1_.nome as nome3_, template1_.ds_perfil as ds_perfil3_,
template1_.pm_perfil as pm_perfil3_, template1_.cnpj as cnpj3_, template1_.id_perfil_pai as id_perfi6_3_ from usuario user0_, perfil template1_,
usuario_status userstatus2_, estado state3_, empresa company4_, empresa company5_ where user0_.id_perfil=template1_.id_perfil
and user0_.id_usuario_status=userstatus2_.id_usuario_status and user0_.uf_rg=state3_.id_estado(+) and ((user0_.login='fcompaq' )and(user0_.senha=
'01ux7/b5aiw=' )and(userstatus2_.id_usuario_status='1' and user0_.id_usuario_status=userstatus2_.id_usuario_status)and(company4_.id_empresa_status
in('A' , 'S' , 'P') and user0_.id_perfil=template1_.id_perfil and template1_.cnpj=company4_.cnpj)and(((company4_.cnpj_pai is null
and user0_.id_perfil=template1_.id_perfil and template1_.cnpj=company4_.cnpj))or(((company4_.cnpj_pai is not null and user0_.id_perfil=template1_.
id_perfil and template1_.cnpj=company4_.cnpj))and((company5_.id_empresa_status in('A' , 'S' , 'P') and user0_.id_perfil=template1_.id_perfil and
template1_.cnpj=company4_.cnpj and company4_.cnpj_pai=company5_.cnpj)))))|cargo0_ = PROGRAMADOR,
cnpj3_ = 16361234000102, cpf0_ = 33807840281, ds_perfil3_ = LIBERA ACESSO AOS USUARIOS DO PONTO DE EMBARQUE, ds_usuar2_2_ = HABILITADO, email0_ =
bogas@hst.com.br, id_estado1_ = 30, id_pais1_ = 8, id_usua10_0_ = 1, id_usuar1_2_ = 1, login0_ = fcompaq, no_estado1_ = RS, nome0_ = US. COMPAQ
FILIAL, nome3_ = MASTER EMBARQUE, pm_perfil3_ = C0A0F800F0D8F6C0FC00F8000000000000000000000000000000000000000000, primeir13_0_ = 1, rg0_ = 54625842,
senha0_ = 01ux7/b5aiw=, uf_rg0_ = 30
1110464221906|0|1|commit||
Conslusão: Usando join fetch no HQL, os objetos dentro de User
são carregados numa única query.
Creio que assim a performance é bem maior.
Falow!!
abraço…
PS: to usando uma api bem legal pra pegar todos os statements gerados pelo hibernate: http://www.p6spy.com