← Foro de Java (Servlets y JSP)

Duda Hibernate

Hilo en el foro de Java (Servlets y JSP) · 15 de Junio del 2006 · 1 respuestas
XerXi15 de Junio del 2006
Pregunta
Buenas,

Tengo una duda sobre hibernate. Sin enrollarme, porqué me funciona el primer método y el segundo no (NOTA: no es error de compilación,el primero me devuelve el objeto correctamente y el segundo no):

=====================================================
1
=====================================================
public static Factura getFactura(int pkid) throws HibernateException
{
Session session = null;
Transaction tx = null;
Factura factura = null;
List lista = null;
try {
session = HibernateUtil.getSessionFactory().getCurrentSession();
tx = session.beginTransaction();
Query q = session.createQuery("From data.beans.Factura as f where f.pkid=" + pkid);
lista = q.list();
factura = (Factura)lista.get(0);

tx.commit();

} catch (Exception e) {
factura = null;
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
throw new HibernateException(e);
} finally {

}
return factura;
}

=====================================================
2
=====================================================
public static Factura getFactura(int pkid) throws HibernateException
{
Session session = null;
Transaction tx = null;
Factura factura = null;
List lista = null;
try {
session = HibernateUtil.getSessionFactory().getCurrentSession();
tx = session.beginTransaction();
factura =(Factura)session.load(Factura.class,new Integer(pkid));

tx.commit();

} catch (Exception e) {
factura = null;
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
throw new HibernateException(e);
} finally {

}
return factura;
}

Respuestas 1

neossoftware15 de Junio del 2006
Al parecer esta correcto podrias poner la excepcion que te tira?????

SAlu2
¿Buscas más hilos como este? Mira el foro de Java (Servlets y JSP) o usa el buscador.