optimization of the session creation file in hibernate?

0

good, I currently have this file that creates my session in hibernate.

my question how could I optimize this, because when I run the application is echoed with the pattern DAO, in each instance of the class that is the creator of the session re-read the configuration file.

    
asked by 16.06.2017 в 15:49
source

1 answer

0

This way you only call the methods and you do not need to be creating the session and transaction every time, in case you need to close the session just call       sesion.close();

private void IniciarOperacion() {
    sesion = HibernateUtil.getSessionFactory().openSession();
    transaccion = sesion.beginTransaction();
}

private void ManejarException(HibernateException e) {
    transaccion.rollback();
    throw new HibernateException("Error en la capa de datos ", e);
}
    
answered by 19.06.2017 в 05:21