Ver Mensaje Individual
  #6 (permalink)  
Antiguo 07/05/2006, 09:44
GreenEyed
 
Fecha de Ingreso: octubre-2003
Mensajes: 3.578
Antigüedad: 21 años, 4 meses
Puntos: 51
Para la documentación, aquí: http://www.hibernate.org/5.html

En cuanto a las excepciones, creo que todas heredan de HibernateException. O si no haz un capturar Exception (no subas hasta Throwable) y así te aseguras de pillar cualquier cosa y cerrar la transaccion siempre.

Lo mejor es encapsular todo el tratamiento en una clase y reutilizarlo por todo, asi no te olvidas nunca de tratar ese caso que luego hace que falle la cosa.

<S>

Yo uso algo tal que así:
Código:
    // Get the session
    Session theSession = null;
    Transaction theTX = null;
    try
    {
      theSession = factory.openSession();
      theTX = theSession.beginTransaction();
      boolean error = false;
      try
      {
        // Ejecucion de las acciones con la sesion Hibernate
        //...
        //...
      }
      catch (Exception e)
      {
       error = true;
       // Informar de error
      }
      if (error && theTX != null)
      {
        try
        {
          theTX.rollback();
        }
        catch (HibernateException he)
        {
         // Informar de error haciendo rollback
        }
      }
      else if (theTX != null)
      {
        try
        {
          theTX.commit();
        }
        catch (HibernateException he)
        {
         // Informar de error haciendo commit
        }
      }
    }
    catch (HibernateException e)
    {
      // Informar de error obteniendo la sesion
    }
    finally
    {
      if (theSession != null)
      {
        try
        {
          theSession.close();
        }
        catch (HibernateException e)
        {
          // Informar de error cerrando la sesión
        }
      }
    }

Última edición por GreenEyed; 07/05/2006 a las 10:42