Por que o JPA sempre sobe todas as classes novamente quando chamo a persistencia.
digamos.
Baseado na classe PersistenceUtil informada na classe
public class PersistenceUtil {
private static final String UNIT_NAME = "banco";
private static EntityManagerFactory FACTORY;
public static final ThreadLocal<EntityManager> SESSION = new ThreadLocal<EntityManager>();
public static EntityManager currentEntityManager() {
EntityManager manager = (EntityManager) SESSION.get();
if (manager == null) {
loadInstance();
manager = FACTORY.createEntityManager();
SESSION.set(manager);
}
return manager;
}
public static void closeEntityManager() {
EntityManager manager = (EntityManager) SESSION.get();
if (manager != null) {
manager.close();
}
SESSION.set(null);
}
private static synchronized void loadInstance() {
if (FACTORY == null) {
FACTORY = Persistence.createEntityManagerFactory(UNIT_NAME);
}
}
}
BsEmpresa a = PersistenceUtil.currentEntityManager().find(BsEmpresa.class, id);
PersistenceUtil.closeEntityManager();
sempre quando chamo o metodo sobe as classes tudo novamente conforme abaixo.
já no hibernate isso não acontece, uma vez que sobe o hibernate.
Isso é normal? Sempre vai ocorrer isso?
Por que imagina são 8 segundos para subir cada vez que chamo o metodo, multiplica isso para 1000 pessoas utilizando a aplicação simultaneamente.
18:32:10,529 INFO [AnnotationBinder] Binding entity from annotated class: entidades.BsClassificacaoFiscal
18:32:10,529 INFO [EntityBinder] Bind entity entidades.BsClassificacaoFiscal on table bs_classificacao_fiscal
18:32:10,533 INFO [AnnotationBinder] Binding entity from annotated class: entidades.BsCliente
18:32:10,533 INFO [EntityBinder] Bind entity entidades.BsCliente on table bs_cliente
18:32:10,545 INFO [AnnotationBinder] Binding entity from annotated class: entidades.BsColaborador
18:32:10,546 INFO [EntityBinder] Bind entity entidades.BsColaborador on table bs_colaborador
18:32:10,560 INFO [AnnotationBinder] Binding entity from annotated class: entidades.BsContatoCli
18:32:10,560 INFO [EntityBinder] Bind entity entidades.BsContatoCli on table bs_contato_cli
18:32:10,565 INFO [AnnotationBinder] Binding entity from annotated class: entidades.BsContatoForn
18:32:10,565 INFO [EntityBinder] Bind entity entidades.BsContatoForn on table bs_contato_forn
18:32:10,567 INFO [AnnotationBinder] Binding entity from annotated class: entidades.BsDepartamento
18:32:10,567 INFO [EntityBinder] Bind entity entidades.BsDepartamento on table bs_departamento
18:32:10,571 INFO [AnnotationBinder] Binding entity from annotated class: entidades.BsEmpresa
18:32:10,571 INFO [EntityBinder] Bind entity entidades.BsEmpresa on table bs_empresa
18:32:10,591 INFO [AnnotationBinder] Binding entity from annotated class: entidades.BsFabricante
18:32:10,591 INFO [EntityBinder] Bind entity entidades.BsFabricante on table bs_fabricante
e vaii........................................
e continua............>>>
18:32:13,961 INFO [TableMetadata] table found: public.bs_vendedor_banco
18:32:13,961 INFO [TableMetadata] columns: [nome_banco, gerente_conta, conta, cod_banco, id_bs_vendedor_banco, agencia, fone, ano_abertura, id_bs_colaborador]
18:32:13,961 INFO [TableMetadata] foreign keys: [relationship15, fkc81e711142958b42]
18:32:13,961 INFO [TableMetadata] indexes: [key11]
18:32:14,028 INFO [TableMetadata] table found: public.sy_cfop
18:32:14,028 INFO [TableMetadata] columns: [id_sy_cfop, cfop]
18:32:14,028 INFO [TableMetadata] foreign keys: []
18:32:14,028 INFO [TableMetadata] indexes: [key20]
18:32:14,088 INFO [TableMetadata] table found: public.sy_classificacao
18:32:14,088 INFO [TableMetadata] columns: [id_sy_classificacao, classificacao]
18:32:14,088 INFO [TableMetadata] foreign keys: []
18:32:14,088 INFO [TableMetadata] indexes: [key17]
18:32:14,150 INFO [TableMetadata] table found: public.sy_estado
18:32:14,150 INFO [TableMetadata] columns: [id_sy_estado, estado]
18:32:14,150 INFO [TableMetadata] foreign keys: []
18:32:14,150 INFO [TableMetadata] indexes: [key8]
18:32:14,232 INFO [TableMetadata] table found: public.sy_imagens
18:32:14,232 INFO [TableMetadata] columns: [id_bs_cliente, id_sy_imagens, imagem]
18:32:14,232 INFO [TableMetadata] foreign keys: [fkcfdbbb87c6ad7922, relationship11]
18:32:14,232 INFO [TableMetadata] indexes: [id_sy_imagens, key10]
18:32:14,295 INFO [TableMetadata] table found: public.sy_municipio
18:32:14,296 INFO [TableMetadata] columns: [id_sy_estado, id_sy_municipio, municipio]
18:32:14,296 INFO [TableMetadata] foreign keys: [fk8af259542ee4727e, relationship1]
18:32:14,296 INFO [TableMetadata] indexes: [key7]
18:32:14,354 INFO [TableMetadata] table found: public.sy_telas
18:32:14,354 INFO [TableMetadata] columns: [ver_perm, caminho, id_sy_telas, descricao, sub_menu, menu]
18:32:14,354 INFO [TableMetadata] foreign keys: []
18:32:14,354 INFO [TableMetadata] indexes: [key22]
18:32:14,414 INFO [TableMetadata] table found: public.sy_tp_cliente
18:32:14,414 INFO [TableMetadata] columns: [tipo_cliente, id_sy_tp_cliente]
18:32:14,414 INFO [TableMetadata] foreign keys: []
18:32:14,414 INFO [TableMetadata] indexes: [key1, id_sy_tp_cliente]
18:32:14,415 INFO [SchemaUpdate] schema update complete