Duda Hibernate
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;
}
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;
}
