Camnbios en PatrocinadorDaoJPA y ProyectoDaoJPA
This commit is contained in:
parent
12b301d8fb
commit
de0d013937
@ -22,14 +22,14 @@ import jakarta.persistence.TypedQuery;
|
||||
*/
|
||||
public class PatrocinadorDaoJPA implements IPatrocinadorDAO {
|
||||
@Override
|
||||
public void crearEntidad(Patrocinador entidad) throws ProyectosIESException{
|
||||
EntityManager gestorEntidades= null;
|
||||
public void crearEntidad(Patrocinador entidad) throws ProyectosIESException {
|
||||
EntityManager gestorEntidades = null;
|
||||
EntityTransaction transaccion = null;
|
||||
|
||||
try {
|
||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||
transaccion = gestorEntidades.getTransaction();
|
||||
transaccion .begin();
|
||||
transaccion.begin();
|
||||
|
||||
gestorEntidades.persist(entidad);
|
||||
|
||||
@ -48,15 +48,16 @@ public class PatrocinadorDaoJPA implements IPatrocinadorDAO {
|
||||
|
||||
@Override
|
||||
public void actualizarEntidad(Patrocinador entidad) throws ProyectosIESException {
|
||||
Transaction transaccion = null;
|
||||
Session sesion = null;
|
||||
EntityManager gestorEntidades = null;
|
||||
EntityTransaction transaccion = null;
|
||||
|
||||
try {
|
||||
sesion = GestorSesionesHibernate.getSession();
|
||||
transaccion = sesion.beginTransaction();
|
||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||
transaccion = gestorEntidades.getTransaction();
|
||||
transaccion.begin();
|
||||
|
||||
if(sesion.contains(entidad))
|
||||
sesion.merge(entidad);
|
||||
if (gestorEntidades.contains(entidad))
|
||||
gestorEntidades.merge(entidad);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
@ -65,8 +66,8 @@ public class PatrocinadorDaoJPA implements IPatrocinadorDAO {
|
||||
}
|
||||
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_ACTUALIZACION);
|
||||
} finally {
|
||||
if (sesion != null) {
|
||||
sesion.close();
|
||||
if (gestorEntidades != null) {
|
||||
gestorEntidades.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -87,7 +88,7 @@ public class PatrocinadorDaoJPA implements IPatrocinadorDAO {
|
||||
|
||||
patrocinador = query.getSingleResult();
|
||||
} catch (NoResultException e) { // no hace nada, devuelve null
|
||||
} catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_CONSULTA);
|
||||
}
|
||||
|
||||
@ -106,5 +107,4 @@ public class PatrocinadorDaoJPA implements IPatrocinadorDAO {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -71,15 +71,16 @@ public class ProyectoDaoJPA implements IProyectoDAO {
|
||||
|
||||
@Override
|
||||
public void actualizarEntidad(Proyecto entidad) throws ProyectosIESException {
|
||||
Transaction transaccion = null;
|
||||
Session sesion = null;
|
||||
EntityManager gestorEntidades= null;
|
||||
EntityTransaction transaccion = null;
|
||||
|
||||
try {
|
||||
sesion = GestorSesionesHibernate.getSession();
|
||||
transaccion = sesion.beginTransaction();
|
||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||
transaccion = gestorEntidades.getTransaction();
|
||||
transaccion .begin();
|
||||
|
||||
if (sesion.contains(entidad))
|
||||
sesion.merge(entidad);
|
||||
if (gestorEntidades.contains(entidad))
|
||||
gestorEntidades.merge(entidad);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
@ -88,8 +89,8 @@ public class ProyectoDaoJPA implements IProyectoDAO {
|
||||
}
|
||||
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_ACTUALIZACION);
|
||||
} finally {
|
||||
if (sesion != null) {
|
||||
sesion.close();
|
||||
if (gestorEntidades != null) {
|
||||
gestorEntidades.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user