From 7be7ca361b41c0384f97239034e9534a2a862db0 Mon Sep 17 00:00:00 2001 From: JotaJota96 <jjap96@gmail.com> Date: Tue, 17 Sep 2019 01:25:15 -0300 Subject: [PATCH] Clases con id autoincremental en BDD (falta quitar variable estatica generadora) --- .../AdministradorJpaController.java | 144 ------------------ .../CanalJpaController.java | 144 ------------------ .../CategoriaJpaController.java | 144 ------------------ .../ComentarioJpaController.java | 144 ------------------ .../ListaDeReproduccionJpaController.java | 144 ------------------ .../ListaPorDefectoJpaController.java | 144 ------------------ .../PersonaJpaController.java | 144 ------------------ .../UsuarioJpaController.java | 144 ------------------ .../ValoracionJpaController.java | 138 ----------------- .../VideoJpaController.java | 144 ------------------ .../exceptions/IllegalOrphanException.java | 20 --- .../NonexistentEntityException.java | 10 -- .../PreexistingEntityException.java | 10 -- .../src/Logica/Clases/Administrador.java | 6 + .../src/Logica/Clases/Canal.java | 3 + .../src/Logica/Clases/Comentario.java | 3 + .../Logica/Clases/ListaDeReproduccion.java | 3 + .../src/Logica/Clases/Valoracion.java | 3 +- .../src/Logica/Clases/Video.java | 3 + 19 files changed, 20 insertions(+), 1475 deletions(-) delete mode 100644 UyTube_aplicacion/src/JPAControllerClasses/AdministradorJpaController.java delete mode 100644 UyTube_aplicacion/src/JPAControllerClasses/CanalJpaController.java delete mode 100644 UyTube_aplicacion/src/JPAControllerClasses/CategoriaJpaController.java delete mode 100644 UyTube_aplicacion/src/JPAControllerClasses/ComentarioJpaController.java delete mode 100644 UyTube_aplicacion/src/JPAControllerClasses/ListaDeReproduccionJpaController.java delete mode 100644 UyTube_aplicacion/src/JPAControllerClasses/ListaPorDefectoJpaController.java delete mode 100644 UyTube_aplicacion/src/JPAControllerClasses/PersonaJpaController.java delete mode 100644 UyTube_aplicacion/src/JPAControllerClasses/UsuarioJpaController.java delete mode 100644 UyTube_aplicacion/src/JPAControllerClasses/ValoracionJpaController.java delete mode 100644 UyTube_aplicacion/src/JPAControllerClasses/VideoJpaController.java delete mode 100644 UyTube_aplicacion/src/JPAControllerClasses/exceptions/IllegalOrphanException.java delete mode 100644 UyTube_aplicacion/src/JPAControllerClasses/exceptions/NonexistentEntityException.java delete mode 100644 UyTube_aplicacion/src/JPAControllerClasses/exceptions/PreexistingEntityException.java diff --git a/UyTube_aplicacion/src/JPAControllerClasses/AdministradorJpaController.java b/UyTube_aplicacion/src/JPAControllerClasses/AdministradorJpaController.java deleted file mode 100644 index 737e7af..0000000 --- a/UyTube_aplicacion/src/JPAControllerClasses/AdministradorJpaController.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package JPAControllerClasses; - -import JPAControllerClasses.exceptions.NonexistentEntityException; -import JPAControllerClasses.exceptions.PreexistingEntityException; -import Logica.Clases.Administrador; -import java.io.Serializable; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - -/** - * - * @author Juan - */ -public class AdministradorJpaController implements Serializable { - - public AdministradorJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Administrador administrador) throws PreexistingEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - em.persist(administrador); - em.getTransaction().commit(); - } catch (Exception ex) { - if (findAdministrador(administrador.getId()) != null) { - throw new PreexistingEntityException("Administrador " + administrador + " already exists.", ex); - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Administrador administrador) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - administrador = em.merge(administrador); - em.getTransaction().commit(); - } catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - int id = administrador.getId(); - if (findAdministrador(id) == null) { - throw new NonexistentEntityException("The administrador with id " + id + " no longer exists."); - } - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(int id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Administrador administrador; - try { - administrador = em.getReference(Administrador.class, id); - administrador.getId(); - } catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The administrador with id " + id + " no longer exists.", enfe); - } - em.remove(administrador); - em.getTransaction().commit(); - } finally { - if (em != null) { - em.close(); - } - } - } - - public List<Administrador> findAdministradorEntities() { - return findAdministradorEntities(true, -1, -1); - } - - public List<Administrador> findAdministradorEntities(int maxResults, int firstResult) { - return findAdministradorEntities(false, maxResults, firstResult); - } - - private List<Administrador> findAdministradorEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Administrador.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } finally { - em.close(); - } - } - - public Administrador findAdministrador(int id) { - EntityManager em = getEntityManager(); - try { - return em.find(Administrador.class, id); - } finally { - em.close(); - } - } - - public int getAdministradorCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root<Administrador> rt = cq.from(Administrador.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } finally { - em.close(); - } - } - -} diff --git a/UyTube_aplicacion/src/JPAControllerClasses/CanalJpaController.java b/UyTube_aplicacion/src/JPAControllerClasses/CanalJpaController.java deleted file mode 100644 index 9fc2664..0000000 --- a/UyTube_aplicacion/src/JPAControllerClasses/CanalJpaController.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package JPAControllerClasses; - -import JPAControllerClasses.exceptions.NonexistentEntityException; -import JPAControllerClasses.exceptions.PreexistingEntityException; -import Logica.Clases.Canal; -import java.io.Serializable; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - -/** - * - * @author Juan - */ -public class CanalJpaController implements Serializable { - - public CanalJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Canal canal) throws PreexistingEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - em.persist(canal); - em.getTransaction().commit(); - } catch (Exception ex) { - if (findCanal(canal.getId()) != null) { - throw new PreexistingEntityException("Canal " + canal + " already exists.", ex); - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Canal canal) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - canal = em.merge(canal); - em.getTransaction().commit(); - } catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - int id = canal.getId(); - if (findCanal(id) == null) { - throw new NonexistentEntityException("The canal with id " + id + " no longer exists."); - } - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(int id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Canal canal; - try { - canal = em.getReference(Canal.class, id); - canal.getId(); - } catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The canal with id " + id + " no longer exists.", enfe); - } - em.remove(canal); - em.getTransaction().commit(); - } finally { - if (em != null) { - em.close(); - } - } - } - - public List<Canal> findCanalEntities() { - return findCanalEntities(true, -1, -1); - } - - public List<Canal> findCanalEntities(int maxResults, int firstResult) { - return findCanalEntities(false, maxResults, firstResult); - } - - private List<Canal> findCanalEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Canal.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } finally { - em.close(); - } - } - - public Canal findCanal(int id) { - EntityManager em = getEntityManager(); - try { - return em.find(Canal.class, id); - } finally { - em.close(); - } - } - - public int getCanalCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root<Canal> rt = cq.from(Canal.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } finally { - em.close(); - } - } - -} diff --git a/UyTube_aplicacion/src/JPAControllerClasses/CategoriaJpaController.java b/UyTube_aplicacion/src/JPAControllerClasses/CategoriaJpaController.java deleted file mode 100644 index 28aa94a..0000000 --- a/UyTube_aplicacion/src/JPAControllerClasses/CategoriaJpaController.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package JPAControllerClasses; - -import JPAControllerClasses.exceptions.NonexistentEntityException; -import JPAControllerClasses.exceptions.PreexistingEntityException; -import Logica.Clases.Categoria; -import java.io.Serializable; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - -/** - * - * @author Juan - */ -public class CategoriaJpaController implements Serializable { - - public CategoriaJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Categoria categoria) throws PreexistingEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - em.persist(categoria); - em.getTransaction().commit(); - } catch (Exception ex) { - if (findCategoria(categoria.getNombre()) != null) { - throw new PreexistingEntityException("Categoria " + categoria + " already exists.", ex); - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Categoria categoria) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - categoria = em.merge(categoria); - em.getTransaction().commit(); - } catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - String id = categoria.getNombre(); - if (findCategoria(id) == null) { - throw new NonexistentEntityException("The categoria with id " + id + " no longer exists."); - } - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(String id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Categoria categoria; - try { - categoria = em.getReference(Categoria.class, id); - categoria.getNombre(); - } catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The categoria with id " + id + " no longer exists.", enfe); - } - em.remove(categoria); - em.getTransaction().commit(); - } finally { - if (em != null) { - em.close(); - } - } - } - - public List<Categoria> findCategoriaEntities() { - return findCategoriaEntities(true, -1, -1); - } - - public List<Categoria> findCategoriaEntities(int maxResults, int firstResult) { - return findCategoriaEntities(false, maxResults, firstResult); - } - - private List<Categoria> findCategoriaEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Categoria.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } finally { - em.close(); - } - } - - public Categoria findCategoria(String id) { - EntityManager em = getEntityManager(); - try { - return em.find(Categoria.class, id); - } finally { - em.close(); - } - } - - public int getCategoriaCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root<Categoria> rt = cq.from(Categoria.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } finally { - em.close(); - } - } - -} diff --git a/UyTube_aplicacion/src/JPAControllerClasses/ComentarioJpaController.java b/UyTube_aplicacion/src/JPAControllerClasses/ComentarioJpaController.java deleted file mode 100644 index d7f3c77..0000000 --- a/UyTube_aplicacion/src/JPAControllerClasses/ComentarioJpaController.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package JPAControllerClasses; - -import JPAControllerClasses.exceptions.NonexistentEntityException; -import JPAControllerClasses.exceptions.PreexistingEntityException; -import Logica.Clases.Comentario; -import java.io.Serializable; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - -/** - * - * @author Juan - */ -public class ComentarioJpaController implements Serializable { - - public ComentarioJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Comentario comentario) throws PreexistingEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - em.persist(comentario); - em.getTransaction().commit(); - } catch (Exception ex) { - if (findComentario(comentario.getId()) != null) { - throw new PreexistingEntityException("Comentario " + comentario + " already exists.", ex); - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Comentario comentario) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - comentario = em.merge(comentario); - em.getTransaction().commit(); - } catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - int id = comentario.getId(); - if (findComentario(id) == null) { - throw new NonexistentEntityException("The comentario with id " + id + " no longer exists."); - } - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(int id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Comentario comentario; - try { - comentario = em.getReference(Comentario.class, id); - comentario.getId(); - } catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The comentario with id " + id + " no longer exists.", enfe); - } - em.remove(comentario); - em.getTransaction().commit(); - } finally { - if (em != null) { - em.close(); - } - } - } - - public List<Comentario> findComentarioEntities() { - return findComentarioEntities(true, -1, -1); - } - - public List<Comentario> findComentarioEntities(int maxResults, int firstResult) { - return findComentarioEntities(false, maxResults, firstResult); - } - - private List<Comentario> findComentarioEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Comentario.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } finally { - em.close(); - } - } - - public Comentario findComentario(int id) { - EntityManager em = getEntityManager(); - try { - return em.find(Comentario.class, id); - } finally { - em.close(); - } - } - - public int getComentarioCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root<Comentario> rt = cq.from(Comentario.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } finally { - em.close(); - } - } - -} diff --git a/UyTube_aplicacion/src/JPAControllerClasses/ListaDeReproduccionJpaController.java b/UyTube_aplicacion/src/JPAControllerClasses/ListaDeReproduccionJpaController.java deleted file mode 100644 index 7454cb1..0000000 --- a/UyTube_aplicacion/src/JPAControllerClasses/ListaDeReproduccionJpaController.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package JPAControllerClasses; - -import JPAControllerClasses.exceptions.NonexistentEntityException; -import JPAControllerClasses.exceptions.PreexistingEntityException; -import Logica.Clases.ListaDeReproduccion; -import java.io.Serializable; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - -/** - * - * @author Juan - */ -public class ListaDeReproduccionJpaController implements Serializable { - - public ListaDeReproduccionJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(ListaDeReproduccion listaDeReproduccion) throws PreexistingEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - em.persist(listaDeReproduccion); - em.getTransaction().commit(); - } catch (Exception ex) { - if (findListaDeReproduccion(listaDeReproduccion.getId()) != null) { - throw new PreexistingEntityException("ListaDeReproduccion " + listaDeReproduccion + " already exists.", ex); - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(ListaDeReproduccion listaDeReproduccion) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - listaDeReproduccion = em.merge(listaDeReproduccion); - em.getTransaction().commit(); - } catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - int id = listaDeReproduccion.getId(); - if (findListaDeReproduccion(id) == null) { - throw new NonexistentEntityException("The listaDeReproduccion with id " + id + " no longer exists."); - } - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(int id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - ListaDeReproduccion listaDeReproduccion; - try { - listaDeReproduccion = em.getReference(ListaDeReproduccion.class, id); - listaDeReproduccion.getId(); - } catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The listaDeReproduccion with id " + id + " no longer exists.", enfe); - } - em.remove(listaDeReproduccion); - em.getTransaction().commit(); - } finally { - if (em != null) { - em.close(); - } - } - } - - public List<ListaDeReproduccion> findListaDeReproduccionEntities() { - return findListaDeReproduccionEntities(true, -1, -1); - } - - public List<ListaDeReproduccion> findListaDeReproduccionEntities(int maxResults, int firstResult) { - return findListaDeReproduccionEntities(false, maxResults, firstResult); - } - - private List<ListaDeReproduccion> findListaDeReproduccionEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(ListaDeReproduccion.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } finally { - em.close(); - } - } - - public ListaDeReproduccion findListaDeReproduccion(int id) { - EntityManager em = getEntityManager(); - try { - return em.find(ListaDeReproduccion.class, id); - } finally { - em.close(); - } - } - - public int getListaDeReproduccionCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root<ListaDeReproduccion> rt = cq.from(ListaDeReproduccion.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } finally { - em.close(); - } - } - -} diff --git a/UyTube_aplicacion/src/JPAControllerClasses/ListaPorDefectoJpaController.java b/UyTube_aplicacion/src/JPAControllerClasses/ListaPorDefectoJpaController.java deleted file mode 100644 index 95e822e..0000000 --- a/UyTube_aplicacion/src/JPAControllerClasses/ListaPorDefectoJpaController.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package JPAControllerClasses; - -import JPAControllerClasses.exceptions.NonexistentEntityException; -import JPAControllerClasses.exceptions.PreexistingEntityException; -import Logica.Clases.ListaPorDefecto; -import java.io.Serializable; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - -/** - * - * @author Juan - */ -public class ListaPorDefectoJpaController implements Serializable { - - public ListaPorDefectoJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(ListaPorDefecto listaPorDefecto) throws PreexistingEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - em.persist(listaPorDefecto); - em.getTransaction().commit(); - } catch (Exception ex) { - if (findListaPorDefecto(listaPorDefecto.getNombre()) != null) { - throw new PreexistingEntityException("ListaPorDefecto " + listaPorDefecto + " already exists.", ex); - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(ListaPorDefecto listaPorDefecto) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - listaPorDefecto = em.merge(listaPorDefecto); - em.getTransaction().commit(); - } catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - String id = listaPorDefecto.getNombre(); - if (findListaPorDefecto(id) == null) { - throw new NonexistentEntityException("The listaPorDefecto with id " + id + " no longer exists."); - } - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(String id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - ListaPorDefecto listaPorDefecto; - try { - listaPorDefecto = em.getReference(ListaPorDefecto.class, id); - listaPorDefecto.getNombre(); - } catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The listaPorDefecto with id " + id + " no longer exists.", enfe); - } - em.remove(listaPorDefecto); - em.getTransaction().commit(); - } finally { - if (em != null) { - em.close(); - } - } - } - - public List<ListaPorDefecto> findListaPorDefectoEntities() { - return findListaPorDefectoEntities(true, -1, -1); - } - - public List<ListaPorDefecto> findListaPorDefectoEntities(int maxResults, int firstResult) { - return findListaPorDefectoEntities(false, maxResults, firstResult); - } - - private List<ListaPorDefecto> findListaPorDefectoEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(ListaPorDefecto.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } finally { - em.close(); - } - } - - public ListaPorDefecto findListaPorDefecto(String id) { - EntityManager em = getEntityManager(); - try { - return em.find(ListaPorDefecto.class, id); - } finally { - em.close(); - } - } - - public int getListaPorDefectoCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root<ListaPorDefecto> rt = cq.from(ListaPorDefecto.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } finally { - em.close(); - } - } - -} diff --git a/UyTube_aplicacion/src/JPAControllerClasses/PersonaJpaController.java b/UyTube_aplicacion/src/JPAControllerClasses/PersonaJpaController.java deleted file mode 100644 index 742bcb5..0000000 --- a/UyTube_aplicacion/src/JPAControllerClasses/PersonaJpaController.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package JPAControllerClasses; - -import JPAControllerClasses.exceptions.NonexistentEntityException; -import JPAControllerClasses.exceptions.PreexistingEntityException; -import Logica.Clases.Persona; -import java.io.Serializable; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - -/** - * - * @author Juan - */ -public class PersonaJpaController implements Serializable { - - public PersonaJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Persona persona) throws PreexistingEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - em.persist(persona); - em.getTransaction().commit(); - } catch (Exception ex) { - if (findPersona(persona.getId()) != null) { - throw new PreexistingEntityException("Persona " + persona + " already exists.", ex); - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Persona persona) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - persona = em.merge(persona); - em.getTransaction().commit(); - } catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - int id = persona.getId(); - if (findPersona(id) == null) { - throw new NonexistentEntityException("The persona with id " + id + " no longer exists."); - } - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(int id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Persona persona; - try { - persona = em.getReference(Persona.class, id); - persona.getId(); - } catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The persona with id " + id + " no longer exists.", enfe); - } - em.remove(persona); - em.getTransaction().commit(); - } finally { - if (em != null) { - em.close(); - } - } - } - - public List<Persona> findPersonaEntities() { - return findPersonaEntities(true, -1, -1); - } - - public List<Persona> findPersonaEntities(int maxResults, int firstResult) { - return findPersonaEntities(false, maxResults, firstResult); - } - - private List<Persona> findPersonaEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Persona.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } finally { - em.close(); - } - } - - public Persona findPersona(int id) { - EntityManager em = getEntityManager(); - try { - return em.find(Persona.class, id); - } finally { - em.close(); - } - } - - public int getPersonaCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root<Persona> rt = cq.from(Persona.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } finally { - em.close(); - } - } - -} diff --git a/UyTube_aplicacion/src/JPAControllerClasses/UsuarioJpaController.java b/UyTube_aplicacion/src/JPAControllerClasses/UsuarioJpaController.java deleted file mode 100644 index 7dd7129..0000000 --- a/UyTube_aplicacion/src/JPAControllerClasses/UsuarioJpaController.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package JPAControllerClasses; - -import JPAControllerClasses.exceptions.NonexistentEntityException; -import JPAControllerClasses.exceptions.PreexistingEntityException; -import Logica.Clases.Usuario; -import java.io.Serializable; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - -/** - * - * @author Juan - */ -public class UsuarioJpaController implements Serializable { - - public UsuarioJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Usuario usuario) throws PreexistingEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - em.persist(usuario); - em.getTransaction().commit(); - } catch (Exception ex) { - if (findUsuario(usuario.getId()) != null) { - throw new PreexistingEntityException("Usuario " + usuario + " already exists.", ex); - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Usuario usuario) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - usuario = em.merge(usuario); - em.getTransaction().commit(); - } catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - int id = usuario.getId(); - if (findUsuario(id) == null) { - throw new NonexistentEntityException("The usuario with id " + id + " no longer exists."); - } - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(int id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Usuario usuario; - try { - usuario = em.getReference(Usuario.class, id); - usuario.getId(); - } catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The usuario with id " + id + " no longer exists.", enfe); - } - em.remove(usuario); - em.getTransaction().commit(); - } finally { - if (em != null) { - em.close(); - } - } - } - - public List<Usuario> findUsuarioEntities() { - return findUsuarioEntities(true, -1, -1); - } - - public List<Usuario> findUsuarioEntities(int maxResults, int firstResult) { - return findUsuarioEntities(false, maxResults, firstResult); - } - - private List<Usuario> findUsuarioEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Usuario.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } finally { - em.close(); - } - } - - public Usuario findUsuario(int id) { - EntityManager em = getEntityManager(); - try { - return em.find(Usuario.class, id); - } finally { - em.close(); - } - } - - public int getUsuarioCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root<Usuario> rt = cq.from(Usuario.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } finally { - em.close(); - } - } - -} diff --git a/UyTube_aplicacion/src/JPAControllerClasses/ValoracionJpaController.java b/UyTube_aplicacion/src/JPAControllerClasses/ValoracionJpaController.java deleted file mode 100644 index a1f009e..0000000 --- a/UyTube_aplicacion/src/JPAControllerClasses/ValoracionJpaController.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package JPAControllerClasses; - -import JPAControllerClasses.exceptions.NonexistentEntityException; -import Logica.Clases.Valoracion; -import java.io.Serializable; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - -/** - * - * @author Juan - */ -public class ValoracionJpaController implements Serializable { - - public ValoracionJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Valoracion valoracion) { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - em.persist(valoracion); - em.getTransaction().commit(); - } finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Valoracion valoracion) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - valoracion = em.merge(valoracion); - em.getTransaction().commit(); - } catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - int id = valoracion.getId(); - if (findValoracion(id) == null) { - throw new NonexistentEntityException("The valoracion with id " + id + " no longer exists."); - } - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(int id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Valoracion valoracion; - try { - valoracion = em.getReference(Valoracion.class, id); - valoracion.getId(); - } catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The valoracion with id " + id + " no longer exists.", enfe); - } - em.remove(valoracion); - em.getTransaction().commit(); - } finally { - if (em != null) { - em.close(); - } - } - } - - public List<Valoracion> findValoracionEntities() { - return findValoracionEntities(true, -1, -1); - } - - public List<Valoracion> findValoracionEntities(int maxResults, int firstResult) { - return findValoracionEntities(false, maxResults, firstResult); - } - - private List<Valoracion> findValoracionEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Valoracion.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } finally { - em.close(); - } - } - - public Valoracion findValoracion(int id) { - EntityManager em = getEntityManager(); - try { - return em.find(Valoracion.class, id); - } finally { - em.close(); - } - } - - public int getValoracionCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root<Valoracion> rt = cq.from(Valoracion.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } finally { - em.close(); - } - } - -} diff --git a/UyTube_aplicacion/src/JPAControllerClasses/VideoJpaController.java b/UyTube_aplicacion/src/JPAControllerClasses/VideoJpaController.java deleted file mode 100644 index 72926f5..0000000 --- a/UyTube_aplicacion/src/JPAControllerClasses/VideoJpaController.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package JPAControllerClasses; - -import JPAControllerClasses.exceptions.NonexistentEntityException; -import JPAControllerClasses.exceptions.PreexistingEntityException; -import Logica.Clases.Video; -import java.io.Serializable; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Query; -import javax.persistence.EntityNotFoundException; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - -/** - * - * @author Juan - */ -public class VideoJpaController implements Serializable { - - public VideoJpaController(EntityManagerFactory emf) { - this.emf = emf; - } - private EntityManagerFactory emf = null; - - public EntityManager getEntityManager() { - return emf.createEntityManager(); - } - - public void create(Video video) throws PreexistingEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - em.persist(video); - em.getTransaction().commit(); - } catch (Exception ex) { - if (findVideo(video.getId()) != null) { - throw new PreexistingEntityException("Video " + video + " already exists.", ex); - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void edit(Video video) throws NonexistentEntityException, Exception { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - video = em.merge(video); - em.getTransaction().commit(); - } catch (Exception ex) { - String msg = ex.getLocalizedMessage(); - if (msg == null || msg.length() == 0) { - int id = video.getId(); - if (findVideo(id) == null) { - throw new NonexistentEntityException("The video with id " + id + " no longer exists."); - } - } - throw ex; - } finally { - if (em != null) { - em.close(); - } - } - } - - public void destroy(int id) throws NonexistentEntityException { - EntityManager em = null; - try { - em = getEntityManager(); - em.getTransaction().begin(); - Video video; - try { - video = em.getReference(Video.class, id); - video.getId(); - } catch (EntityNotFoundException enfe) { - throw new NonexistentEntityException("The video with id " + id + " no longer exists.", enfe); - } - em.remove(video); - em.getTransaction().commit(); - } finally { - if (em != null) { - em.close(); - } - } - } - - public List<Video> findVideoEntities() { - return findVideoEntities(true, -1, -1); - } - - public List<Video> findVideoEntities(int maxResults, int firstResult) { - return findVideoEntities(false, maxResults, firstResult); - } - - private List<Video> findVideoEntities(boolean all, int maxResults, int firstResult) { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - cq.select(cq.from(Video.class)); - Query q = em.createQuery(cq); - if (!all) { - q.setMaxResults(maxResults); - q.setFirstResult(firstResult); - } - return q.getResultList(); - } finally { - em.close(); - } - } - - public Video findVideo(int id) { - EntityManager em = getEntityManager(); - try { - return em.find(Video.class, id); - } finally { - em.close(); - } - } - - public int getVideoCount() { - EntityManager em = getEntityManager(); - try { - CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); - Root<Video> rt = cq.from(Video.class); - cq.select(em.getCriteriaBuilder().count(rt)); - Query q = em.createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } finally { - em.close(); - } - } - -} diff --git a/UyTube_aplicacion/src/JPAControllerClasses/exceptions/IllegalOrphanException.java b/UyTube_aplicacion/src/JPAControllerClasses/exceptions/IllegalOrphanException.java deleted file mode 100644 index 3b58e83..0000000 --- a/UyTube_aplicacion/src/JPAControllerClasses/exceptions/IllegalOrphanException.java +++ /dev/null @@ -1,20 +0,0 @@ -package JPAControllerClasses.exceptions; - -import java.util.ArrayList; -import java.util.List; - -public class IllegalOrphanException extends Exception { - private List<String> messages; - public IllegalOrphanException(List<String> messages) { - super((messages != null && messages.size() > 0 ? messages.get(0) : null)); - if (messages == null) { - this.messages = new ArrayList<String>(); - } - else { - this.messages = messages; - } - } - public List<String> getMessages() { - return messages; - } -} diff --git a/UyTube_aplicacion/src/JPAControllerClasses/exceptions/NonexistentEntityException.java b/UyTube_aplicacion/src/JPAControllerClasses/exceptions/NonexistentEntityException.java deleted file mode 100644 index 4722e10..0000000 --- a/UyTube_aplicacion/src/JPAControllerClasses/exceptions/NonexistentEntityException.java +++ /dev/null @@ -1,10 +0,0 @@ -package JPAControllerClasses.exceptions; - -public class NonexistentEntityException extends Exception { - public NonexistentEntityException(String message, Throwable cause) { - super(message, cause); - } - public NonexistentEntityException(String message) { - super(message); - } -} diff --git a/UyTube_aplicacion/src/JPAControllerClasses/exceptions/PreexistingEntityException.java b/UyTube_aplicacion/src/JPAControllerClasses/exceptions/PreexistingEntityException.java deleted file mode 100644 index 6e3acce..0000000 --- a/UyTube_aplicacion/src/JPAControllerClasses/exceptions/PreexistingEntityException.java +++ /dev/null @@ -1,10 +0,0 @@ -package JPAControllerClasses.exceptions; - -public class PreexistingEntityException extends Exception { - public PreexistingEntityException(String message, Throwable cause) { - super(message, cause); - } - public PreexistingEntityException(String message) { - super(message); - } -} diff --git a/UyTube_aplicacion/src/Logica/Clases/Administrador.java b/UyTube_aplicacion/src/Logica/Clases/Administrador.java index 5d72cf7..92b3b06 100644 --- a/UyTube_aplicacion/src/Logica/Clases/Administrador.java +++ b/UyTube_aplicacion/src/Logica/Clases/Administrador.java @@ -1,7 +1,10 @@ package Logica.Clases; import java.io.Serializable; +import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; @@ -11,6 +14,9 @@ public class Administrador extends Persona implements Serializable{ private static int contadorAdministrador = 1; @Id + // No logre hacer que el id fuera auto-incremental, no se por que, probe de todo y no pude + //@GeneratedValue(strategy=GenerationType.IDENTITY) + //@Column(name = "id") private int id; //------------------------------------------------------------------------- diff --git a/UyTube_aplicacion/src/Logica/Clases/Canal.java b/UyTube_aplicacion/src/Logica/Clases/Canal.java index 3416de7..8485ffc 100644 --- a/UyTube_aplicacion/src/Logica/Clases/Canal.java +++ b/UyTube_aplicacion/src/Logica/Clases/Canal.java @@ -16,6 +16,8 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; @@ -27,6 +29,7 @@ public class Canal implements Serializable { private static int contadorCanal = 1; @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name = "id") private int id; diff --git a/UyTube_aplicacion/src/Logica/Clases/Comentario.java b/UyTube_aplicacion/src/Logica/Clases/Comentario.java index be2d5c1..f1e297a 100644 --- a/UyTube_aplicacion/src/Logica/Clases/Comentario.java +++ b/UyTube_aplicacion/src/Logica/Clases/Comentario.java @@ -9,6 +9,8 @@ import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; @@ -21,6 +23,7 @@ public class Comentario implements Serializable { private static int contadorComentarios = 1; @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name = "id") private int id; diff --git a/UyTube_aplicacion/src/Logica/Clases/ListaDeReproduccion.java b/UyTube_aplicacion/src/Logica/Clases/ListaDeReproduccion.java index 0f4848c..7c6f78f 100644 --- a/UyTube_aplicacion/src/Logica/Clases/ListaDeReproduccion.java +++ b/UyTube_aplicacion/src/Logica/Clases/ListaDeReproduccion.java @@ -13,6 +13,8 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; @@ -25,6 +27,7 @@ public class ListaDeReproduccion implements Serializable { private static int contadorListasDeReproduccion = 1; @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name = "id") private int id; diff --git a/UyTube_aplicacion/src/Logica/Clases/Valoracion.java b/UyTube_aplicacion/src/Logica/Clases/Valoracion.java index 97ec9bb..3177791 100644 --- a/UyTube_aplicacion/src/Logica/Clases/Valoracion.java +++ b/UyTube_aplicacion/src/Logica/Clases/Valoracion.java @@ -4,6 +4,7 @@ import Logica.DataType.DtValoracion; import Logica.Enumerados.TipoValoracion; import java.io.Serializable; import javax.persistence.CascadeType; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -20,7 +21,7 @@ public class Valoracion implements Serializable { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) - @JoinColumn(name = "id") + @Column(name = "id") private int id; @Enumerated(EnumType.STRING) diff --git a/UyTube_aplicacion/src/Logica/Clases/Video.java b/UyTube_aplicacion/src/Logica/Clases/Video.java index 4b1a319..d06af75 100644 --- a/UyTube_aplicacion/src/Logica/Clases/Video.java +++ b/UyTube_aplicacion/src/Logica/Clases/Video.java @@ -17,6 +17,8 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; @@ -28,6 +30,7 @@ public class Video implements Serializable { private static int idActual = 1; @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name = "id") private int id; -- GitLab