commit inicial
This commit is contained in:
commit
2aae5617cd
41
.classpath
Normal file
41
.classpath
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-25">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/bin/
|
||||
*.class
|
||||
/target/
|
||||
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>aadd_act3_5</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
2
.settings/org.eclipse.core.resources.prefs
Normal file
2
.settings/org.eclipse.core.resources.prefs
Normal file
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
13
.settings/org.eclipse.jdt.core.prefs
Normal file
13
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,13 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=24
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=24
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=24
|
||||
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
23
pom.xml
Normal file
23
pom.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.lapaloma.aadd.cine</groupId>
|
||||
<artifactId>aadd_act3_2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>9.5.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-core -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate.orm</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>7.1.11.Final</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
212
src/main/java/org/lapaloma/aadd/cine/AppCine.java
Normal file
212
src/main/java/org/lapaloma/aadd/cine/AppCine.java
Normal file
@ -0,0 +1,212 @@
|
||||
package org.lapaloma.aadd.cine;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import org.lapaloma.aadd.cine.dao.IOperacionesDAOEntidad;
|
||||
import org.lapaloma.aadd.cine.dao.hbnt.ActorDaoHibernate;
|
||||
import org.lapaloma.aadd.cine.dao.hbnt.ContinenteDaoHibernate;
|
||||
import org.lapaloma.aadd.cine.dao.hbnt.DirectorDaoHibernate;
|
||||
import org.lapaloma.aadd.cine.dao.hbnt.PaisDaoHibernate;
|
||||
import org.lapaloma.aadd.cine.dao.hbnt.PeliculaDaoHibernate;
|
||||
import org.lapaloma.aadd.cine.vo.Actor;
|
||||
import org.lapaloma.aadd.cine.vo.Continente;
|
||||
import org.lapaloma.aadd.cine.vo.Director;
|
||||
import org.lapaloma.aadd.cine.vo.Pais;
|
||||
import org.lapaloma.aadd.cine.vo.Pelicula;
|
||||
|
||||
/**
|
||||
*
|
||||
* AppMapaMundi: Clase que realiza ....
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 5 dic 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class AppCine {
|
||||
|
||||
public static void main(String[] args) {
|
||||
AppCine app = new AppCine();
|
||||
|
||||
// app.probarOperacionesContinente();
|
||||
|
||||
// app.probarOperacionesPais();
|
||||
|
||||
// app.probarOperacionesDirector();
|
||||
|
||||
app.probarOperacionesPelicula();
|
||||
|
||||
app.probarOperacionesActor();
|
||||
|
||||
app.probarOperacionesReparto();
|
||||
|
||||
}
|
||||
|
||||
private void probarOperacionesContinente() {
|
||||
IOperacionesDAOEntidad<Continente, String> iDaoContinente = new ContinenteDaoHibernate();
|
||||
|
||||
// Lista de Continentes
|
||||
List<Continente> listaCcontinentes = iDaoContinente.obtenerListaTodasEntidades();
|
||||
System.out.println("obtenerListaTodasEntidades: " + listaCcontinentes);
|
||||
|
||||
// Continente por ID
|
||||
Continente continente = iDaoContinente.obtenerEntidadPorClave("02");
|
||||
System.out.println("obtenerEntidadPorID: " + continente);
|
||||
|
||||
// Insertar continente
|
||||
Continente continente2 = new Continente();
|
||||
continente2.setCodigo("06");
|
||||
continente2.setNombre("Antartida");
|
||||
iDaoContinente.crearEntidad(continente2);
|
||||
System.out.println("crearEntidad: " + continente2);
|
||||
|
||||
// Actualizar continente
|
||||
continente.setNombre("América del norte y del sur");
|
||||
iDaoContinente.actualizarEntidad(continente);
|
||||
System.out.println("actualizarEntidad: " + continente);
|
||||
|
||||
// Borrar continente
|
||||
iDaoContinente.borrarEntidadPorClave("01");
|
||||
}
|
||||
|
||||
private void probarOperacionesPais() {
|
||||
IOperacionesDAOEntidad<Pais, Integer> iDaoPais = new PaisDaoHibernate();
|
||||
|
||||
// Lista de Paises
|
||||
List<Pais> listaPaises = iDaoPais.obtenerListaTodasEntidades();
|
||||
System.out.println("obtenerListaTodasEntidades: " + listaPaises);
|
||||
|
||||
// Pais por ID
|
||||
Pais pais = iDaoPais.obtenerEntidadPorClave(152);
|
||||
System.out.println("obtenerEntidadPorID: " + pais);
|
||||
|
||||
// Insertar Pais
|
||||
Pais pais2 = new Pais();
|
||||
Continente continente = new Continente();
|
||||
continente.setCodigo("04");
|
||||
pais2.setIdentificador(200);
|
||||
pais2.setNombrePais("El país de la Maravillas");
|
||||
pais2.setCapital("Wonderland");
|
||||
pais2.setContinente(continente);
|
||||
iDaoPais.crearEntidad(pais2);
|
||||
System.out.println("crearEntidad: " + pais2);
|
||||
|
||||
// Actualizar Pais
|
||||
pais.setCapital("Magerit");
|
||||
iDaoPais.actualizarEntidad(pais);
|
||||
System.out.println("actualizarEntidad: " + pais);
|
||||
|
||||
// Borrar Pais
|
||||
iDaoPais.borrarEntidadPorClave(147);
|
||||
}
|
||||
|
||||
private void probarOperacionesDirector() {
|
||||
IOperacionesDAOEntidad<Director, Integer> iDaoDirector = new DirectorDaoHibernate();
|
||||
|
||||
// Lista de Directores
|
||||
List<Director> listaDirectores = iDaoDirector.obtenerListaTodasEntidades();
|
||||
System.out.println("obtenerListaTodasEntidades: " + listaDirectores);
|
||||
|
||||
// Director por ID
|
||||
Director director = iDaoDirector.obtenerEntidadPorClave(1);
|
||||
System.out.println("obtenerEntidadPorID: " + director);
|
||||
|
||||
// Insertar Director
|
||||
// Pais por ID
|
||||
IOperacionesDAOEntidad<Pais, Integer> iDaoPais = new PaisDaoHibernate();
|
||||
Pais pais = iDaoPais.obtenerEntidadPorClave(152);
|
||||
|
||||
Director director2 = new Director();
|
||||
LocalDate fechaNacimiento = LocalDate.of(1973, 5, 9);
|
||||
director2.setFechaNacimiento(fechaNacimiento);
|
||||
director2.setNombre("Rodrigo Cortés");
|
||||
director2.setPais(pais);
|
||||
iDaoDirector.crearEntidad(director2);
|
||||
System.out.println("crearEntidad: " + director2);
|
||||
|
||||
// Actualizar Director
|
||||
director.setNombre("Woody Aaallen");
|
||||
iDaoDirector.actualizarEntidad(director);
|
||||
System.out.println("actualizarEntidad: " + director);
|
||||
|
||||
// Borrar Director
|
||||
iDaoDirector.borrarEntidadPorClave(3);
|
||||
}
|
||||
|
||||
private void probarOperacionesPelicula() {
|
||||
IOperacionesDAOEntidad<Pelicula, Integer> iDaoPelicula = new PeliculaDaoHibernate();
|
||||
|
||||
// Lista de Peliculas
|
||||
List<Pelicula> listaPeliculas = iDaoPelicula.obtenerListaTodasEntidades();
|
||||
System.out.println("obtenerListaTodasEntidades: " + listaPeliculas);
|
||||
|
||||
// Pelicula por ID
|
||||
Pelicula pelicula = iDaoPelicula.obtenerEntidadPorClave(3);
|
||||
System.out.println("obtenerEntidadPorID: " + pelicula);
|
||||
|
||||
// Insertar Director
|
||||
// Director por ID
|
||||
IOperacionesDAOEntidad<Director, Integer> iDaoDirector = new DirectorDaoHibernate();
|
||||
Director director = iDaoDirector.obtenerEntidadPorClave(1);
|
||||
// Pais por ID
|
||||
IOperacionesDAOEntidad<Pais, Integer> iDaoPais = new PaisDaoHibernate();
|
||||
Pais paisLocalizacion = iDaoPais.obtenerEntidadPorClave(152);
|
||||
|
||||
Pelicula pelicula2 = new Pelicula();
|
||||
pelicula2.setTitulo("Midnight in Paris");
|
||||
pelicula2.setPaisLocalizacion(paisLocalizacion);
|
||||
pelicula2.setDirector(director);
|
||||
pelicula2.setAnyo(2011);
|
||||
pelicula2.setColor(true);
|
||||
pelicula2.setIdioma("Inglés");
|
||||
pelicula2.setObservacion("No relevantes");
|
||||
iDaoPelicula.crearEntidad(pelicula2);
|
||||
System.out.println("crearEntidad: " + pelicula2);
|
||||
|
||||
// Actualizar Película
|
||||
pelicula2.setObservacion("Hay breves escenas ambientadas en Versalles");
|
||||
iDaoPelicula.actualizarEntidad(pelicula2);
|
||||
System.out.println("actualizarEntidad: " + director);
|
||||
|
||||
// Borrar Película
|
||||
iDaoPelicula.borrarEntidadPorClave(3);
|
||||
}
|
||||
|
||||
private void probarOperacionesActor() {
|
||||
IOperacionesDAOEntidad<Actor, Integer> iDaoActor = new ActorDaoHibernate();
|
||||
|
||||
// Lista de Actores
|
||||
List<Actor> listaActores = iDaoActor.obtenerListaTodasEntidades();
|
||||
System.out.println("obtenerListaTodasEntidades: " + listaActores);
|
||||
|
||||
// Actor por ID
|
||||
Actor actor = iDaoActor.obtenerEntidadPorClave(3);
|
||||
System.out.println("obtenerEntidadPorID: " + actor);
|
||||
|
||||
// Insertar Actor
|
||||
// Pais por ID
|
||||
IOperacionesDAOEntidad<Pais, Integer> iDaoPais = new PaisDaoHibernate();
|
||||
Pais paisLocalizacion = iDaoPais.obtenerEntidadPorClave(152);
|
||||
|
||||
Actor actor2 = new Actor();
|
||||
actor2.set
|
||||
iDaoActor.crearEntidad(pelicula2);
|
||||
System.out.println("crearEntidad: " + pelicula2);
|
||||
|
||||
// Actualizar Actor
|
||||
actor2.set
|
||||
iDaoActor.actualizarEntidad(pelicula2);
|
||||
System.out.println("actualizarEntidad: " + director);
|
||||
|
||||
// Borrar Actor
|
||||
iDaoActor.borrarEntidadPorClave(3);
|
||||
}
|
||||
|
||||
private void probarOperacionesReparto() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package org.lapaloma.aadd.cine.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* IOperacionesBasicas: Clase que realiza ....
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 14 dic 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public interface IOperacionesDAOEntidad<T, ID> {
|
||||
T obtenerEntidadPorClave(ID clave);
|
||||
List<T> obtenerListaTodasEntidades();
|
||||
void crearEntidad(T entidad);
|
||||
void actualizarEntidad(T entidad);
|
||||
void borrarEntidadPorClave(ID clave);
|
||||
}
|
||||
|
||||
@ -0,0 +1,113 @@
|
||||
package org.lapaloma.aadd.cine.dao.hbnt;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.query.MutationQuery;
|
||||
import org.hibernate.query.SelectionQuery;
|
||||
import org.lapaloma.aadd.cine.dao.IOperacionesDAOEntidad;
|
||||
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||
import org.lapaloma.aadd.cine.vo.Actor;
|
||||
|
||||
/**
|
||||
*
|
||||
* ActorDaoHibernate: Clase que implementa las operaciones del interfaz
|
||||
* IOperacionesDAOEntidad de Actor para Hibernate.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 14 dic 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class ActorDaoHibernate implements IOperacionesDAOEntidad<Actor, Integer> {
|
||||
|
||||
@Override
|
||||
public Actor obtenerEntidadPorClave(Integer clave) {
|
||||
Actor actor = null;
|
||||
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
actor = sesion.find(Actor.class, clave);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return actor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Actor> obtenerListaTodasEntidades() {
|
||||
List<Actor> listaActores = null;
|
||||
String sentenciaHQL = "SELECT d FROM Pelicula d";
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
|
||||
SelectionQuery<Actor> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Actor.class);
|
||||
listaActores = sentenciaConsulta.getResultList();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return listaActores;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void crearEntidad(Actor entidad) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
// try con recursos "cerrables": Connection, Statement
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
sesion.persist(entidad);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actualizarEntidad(Actor entidad) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
if (!sesion.contains(entidad))
|
||||
sesion.merge(entidad);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void borrarEntidadPorClave(Integer clave) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
// Borrado de Repartos de un Actor
|
||||
String sentenciaBorradoRepartosHQL = "DELETE FROM Reparto r WHERE r.actor.identificador = :identificador";
|
||||
MutationQuery senteciaBorradoRepartos = sesion.createMutationQuery(sentenciaBorradoRepartosHQL);
|
||||
senteciaBorradoRepartos.setParameter("identificador", clave);
|
||||
senteciaBorradoRepartos.executeUpdate();
|
||||
|
||||
// Borrado de Actor
|
||||
String sentenciaBorradoActorHQL = "DELETE FROM Actor p WHERE identificador = :identificador";
|
||||
MutationQuery senteciaBorradoActor = sesion.createMutationQuery(sentenciaBorradoActorHQL);
|
||||
senteciaBorradoActor.setParameter("identificador", clave);
|
||||
senteciaBorradoActor.executeUpdate();
|
||||
|
||||
transaccion.commit();
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,116 @@
|
||||
package org.lapaloma.aadd.cine.dao.hbnt;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.query.MutationQuery;
|
||||
import org.hibernate.query.SelectionQuery;
|
||||
import org.lapaloma.aadd.cine.dao.IOperacionesDAOEntidad;
|
||||
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||
import org.lapaloma.aadd.cine.vo.Continente;
|
||||
|
||||
/**
|
||||
*
|
||||
* ContinenteDaoHibernate: Clase que implementa las operaciones del interfaz IOperacionesDAOEntidad
|
||||
* de Continente para Hibernate.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 14 dic 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class ContinenteDaoHibernate implements IOperacionesDAOEntidad<Continente, String> {
|
||||
|
||||
@Override
|
||||
public Continente obtenerEntidadPorClave(String clave) {
|
||||
Continente continente = null;
|
||||
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
continente = sesion.find(Continente.class, clave);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return continente;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Continente> obtenerListaTodasEntidades() {
|
||||
List<Continente> listaContinentes = null;
|
||||
String sentenciaHQL = "SELECT c FROM Continente c";
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
|
||||
SelectionQuery<Continente> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Continente.class);
|
||||
listaContinentes = sentenciaConsulta.getResultList();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return listaContinentes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void crearEntidad(Continente entidad) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
// try con recursos "cerrables": Connection, Statement
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
sesion.persist(entidad);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actualizarEntidad(Continente entidad) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
if (!sesion.contains(entidad))
|
||||
sesion.merge(entidad);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void borrarEntidadPorClave(String clave) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
String sentenciaBorradoPaiseesHQL = "DELETE FROM Pais p WHERE p.continente.codigo = :codigo";
|
||||
MutationQuery senteciaBorradoPaises = sesion.createMutationQuery(sentenciaBorradoPaiseesHQL);
|
||||
senteciaBorradoPaises.setParameter("codigo", clave);
|
||||
senteciaBorradoPaises.executeUpdate();
|
||||
|
||||
String sentenciaBorradoContinenteHQL = "DELETE FROM Continente WHERE codigo= :codigo";
|
||||
MutationQuery sentenciaBorradoContinente = sesion.createMutationQuery(sentenciaBorradoContinenteHQL);
|
||||
sentenciaBorradoContinente.setParameter("codigo", clave);
|
||||
sentenciaBorradoContinente.executeUpdate();
|
||||
|
||||
/*
|
||||
* Continente continente = sesion.find(Continente.class, codigo);
|
||||
* sesion.remove(continente);
|
||||
*/
|
||||
transaccion.commit();
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,120 @@
|
||||
package org.lapaloma.aadd.cine.dao.hbnt;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.query.MutationQuery;
|
||||
import org.hibernate.query.SelectionQuery;
|
||||
import org.lapaloma.aadd.cine.dao.IOperacionesDAOEntidad;
|
||||
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||
import org.lapaloma.aadd.cine.vo.Director;
|
||||
|
||||
/**
|
||||
*
|
||||
* DirectorDAO: Clase que implementa las operaciones del interfaz
|
||||
* IOperacionesDAOEntidad de Director para Hibernate.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 14 dic 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class DirectorDaoHibernate implements IOperacionesDAOEntidad<Director, Integer> {
|
||||
|
||||
@Override
|
||||
public Director obtenerEntidadPorClave(Integer clave) {
|
||||
Director director = null;
|
||||
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
director = sesion.find(Director.class, clave);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return director;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Director> obtenerListaTodasEntidades() {
|
||||
List<Director> listaDirectores = null;
|
||||
String sentenciaHQL = "SELECT d FROM Director d";
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
|
||||
SelectionQuery<Director> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Director.class);
|
||||
listaDirectores = sentenciaConsulta.getResultList();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return listaDirectores;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void crearEntidad(Director entidad) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
// try con recursos "cerrables": Connection, Statement
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
sesion.persist(entidad);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actualizarEntidad(Director entidad) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
if (!sesion.contains(entidad))
|
||||
sesion.merge(entidad);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void borrarEntidadPorClave(Integer clave) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
//Borrado de Repartos de películas un director
|
||||
String sentenciaBorradoRepartosHQL = "DELETE FROM Reparto r WHERE r.pelicula.director.identificador = :identificador";
|
||||
MutationQuery senteciaBorradoRepartos = sesion.createMutationQuery(sentenciaBorradoRepartosHQL);
|
||||
senteciaBorradoRepartos.setParameter("identificador", clave);
|
||||
senteciaBorradoRepartos.executeUpdate();
|
||||
|
||||
// Borrado de Películas de un director
|
||||
String sentenciaBorradoPeliculasHQL = "DELETE FROM Pelicula p WHERE p.director.identificador = :identificador";
|
||||
MutationQuery senteciaBorradoPeliculas = sesion.createMutationQuery(sentenciaBorradoPeliculasHQL);
|
||||
senteciaBorradoPeliculas.setParameter("identificador", clave);
|
||||
senteciaBorradoPeliculas.executeUpdate();
|
||||
|
||||
String sentenciaBorradoDirectoresHQL = "DELETE FROM Director d WHERE d.identificador = :identificador";
|
||||
MutationQuery senteciaBorradoDirectores = sesion.createMutationQuery(sentenciaBorradoDirectoresHQL);
|
||||
senteciaBorradoDirectores.setParameter("identificador", clave);
|
||||
senteciaBorradoDirectores.executeUpdate();
|
||||
/*
|
||||
* Pais continente = sesion.find(Pais.class, clave); sesion.remove(continente);
|
||||
*/
|
||||
transaccion.commit();
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,110 @@
|
||||
package org.lapaloma.aadd.cine.dao.hbnt;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.query.MutationQuery;
|
||||
import org.hibernate.query.SelectionQuery;
|
||||
import org.lapaloma.aadd.cine.dao.IOperacionesDAOEntidad;
|
||||
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||
import org.lapaloma.aadd.cine.vo.Pais;
|
||||
|
||||
/**
|
||||
*
|
||||
* PaisDaoHibernate: Clase que implementa las operaciones del interfaz IOperacionesDAOEntidad
|
||||
* de Pais para Hibernate.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 14 dic 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class PaisDaoHibernate implements IOperacionesDAOEntidad<Pais, Integer> {
|
||||
|
||||
@Override
|
||||
public Pais obtenerEntidadPorClave(Integer clave) {
|
||||
Pais pais = null;
|
||||
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
pais = sesion.find(Pais.class, clave);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return pais;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pais> obtenerListaTodasEntidades() {
|
||||
List<Pais> listaPaises = null;
|
||||
String sentenciaHQL = "SELECT p FROM Pais p";
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
|
||||
SelectionQuery<Pais> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Pais.class);
|
||||
listaPaises = sentenciaConsulta.getResultList();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return listaPaises;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void crearEntidad(Pais entidad) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
// try con recursos "cerrables": Connection, Statement
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
sesion.persist(entidad);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actualizarEntidad(Pais entidad) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
if (!sesion.contains(entidad))
|
||||
sesion.merge(entidad);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void borrarEntidadPorClave(Integer clave) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
String sentenciaBorradoPaisesHQL = "DELETE FROM Pais p WHERE p.identificador = :identificador";
|
||||
MutationQuery senteciaBorradoPaises = sesion.createMutationQuery(sentenciaBorradoPaisesHQL);
|
||||
senteciaBorradoPaises.setParameter("identificador", clave);
|
||||
senteciaBorradoPaises.executeUpdate();
|
||||
/*
|
||||
Pais continente = sesion.find(Pais.class, clave);
|
||||
sesion.remove(continente);
|
||||
*/
|
||||
transaccion.commit();
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,113 @@
|
||||
package org.lapaloma.aadd.cine.dao.hbnt;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.query.MutationQuery;
|
||||
import org.hibernate.query.SelectionQuery;
|
||||
import org.lapaloma.aadd.cine.dao.IOperacionesDAOEntidad;
|
||||
import org.lapaloma.aadd.cine.gestores.GestorSesionesHibernate;
|
||||
import org.lapaloma.aadd.cine.vo.Pelicula;
|
||||
|
||||
/**
|
||||
*
|
||||
* PeliculaDAO: Clase que implementa las operaciones del interfaz
|
||||
* IOperacionesDAOEntidad de Pelicula para Hibernate.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 14 dic 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class PeliculaDaoHibernate implements IOperacionesDAOEntidad<Pelicula, Integer> {
|
||||
|
||||
@Override
|
||||
public Pelicula obtenerEntidadPorClave(Integer clave) {
|
||||
Pelicula pelicula = null;
|
||||
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
pelicula = sesion.find(Pelicula.class, clave);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return pelicula;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pelicula> obtenerListaTodasEntidades() {
|
||||
List<Pelicula> listaPeliculas = null;
|
||||
String sentenciaHQL = "SELECT d FROM Pelicula d";
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
|
||||
SelectionQuery<Pelicula> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Pelicula.class);
|
||||
listaPeliculas = sentenciaConsulta.getResultList();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return listaPeliculas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void crearEntidad(Pelicula entidad) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
// try con recursos "cerrables": Connection, Statement
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
sesion.persist(entidad);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actualizarEntidad(Pelicula entidad) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
// try con recursos "cerrables": Session
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
if (!sesion.contains(entidad))
|
||||
sesion.merge(entidad);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void borrarEntidadPorClave(Integer clave) {
|
||||
Transaction transaccion = null;
|
||||
|
||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||
transaccion = sesion.beginTransaction();
|
||||
// Borrado de Repartos de una Película
|
||||
String sentenciaBorradoRepartosHQL = "DELETE FROM Reparto r WHERE r.pelicula.identificador = :identificador";
|
||||
MutationQuery senteciaBorradoRepartos = sesion.createMutationQuery(sentenciaBorradoRepartosHQL);
|
||||
senteciaBorradoRepartos.setParameter("identificador", clave);
|
||||
senteciaBorradoRepartos.executeUpdate();
|
||||
|
||||
// Borrado de Películas de una Película
|
||||
String sentenciaBorradoPeliculasHQL = "DELETE FROM Pelicula p WHERE identificador = :identificador";
|
||||
MutationQuery senteciaBorradoPeliculas = sesion.createMutationQuery(sentenciaBorradoPeliculasHQL);
|
||||
senteciaBorradoPeliculas.setParameter("identificador", clave);
|
||||
senteciaBorradoPeliculas.executeUpdate();
|
||||
|
||||
transaccion.commit();
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package org.lapaloma.aadd.cine.gestores;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
/**
|
||||
*
|
||||
* GestorSesionesHibernate: Clase que realiza ....
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 4 dic 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class GestorSesionesHibernate {
|
||||
private static SessionFactory sessionFactory = null;
|
||||
|
||||
private GestorSesionesHibernate() {// Constructor privado para evitar instanciación
|
||||
}
|
||||
|
||||
// Carga la configuración desde hibernate.cfg.xml
|
||||
static {
|
||||
try {
|
||||
sessionFactory = new Configuration().configure().buildSessionFactory();
|
||||
} catch (Throwable ex) {
|
||||
System.err.println("Error en SessionFactory: " + ex);
|
||||
throw new ExceptionInInitializerError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Session getSession() {
|
||||
return sessionFactory.openSession();
|
||||
}
|
||||
|
||||
public static void cerrarFactoria() {
|
||||
if (sessionFactory != null) {
|
||||
sessionFactory.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
20
src/main/java/org/lapaloma/aadd/cine/vo/Actor.java
Normal file
20
src/main/java/org/lapaloma/aadd/cine/vo/Actor.java
Normal file
@ -0,0 +1,20 @@
|
||||
package org.lapaloma.aadd.cine.vo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "actor")
|
||||
public class Actor {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name="identificador")
|
||||
private Integer identificador;
|
||||
|
||||
@Column(name="nombre", length = 50)
|
||||
private String nombre;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "id_pais")
|
||||
private Pais pais;
|
||||
|
||||
}
|
||||
39
src/main/java/org/lapaloma/aadd/cine/vo/Continente.java
Normal file
39
src/main/java/org/lapaloma/aadd/cine/vo/Continente.java
Normal file
@ -0,0 +1,39 @@
|
||||
package org.lapaloma.aadd.cine.vo;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "continente")
|
||||
public class Continente {
|
||||
@Id
|
||||
@Column(name = "codigo", columnDefinition = "char(2)")
|
||||
private String codigo;
|
||||
|
||||
@Column(name = "nombre_continente ", length = 50)
|
||||
private String nombre;
|
||||
|
||||
public String getCodigo() {
|
||||
return codigo;
|
||||
}
|
||||
|
||||
public void setCodigo(String codigo) {
|
||||
this.codigo = codigo;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Continente [codigo=" + codigo + ", nombre=" + nombre + "]\n";
|
||||
}
|
||||
|
||||
}
|
||||
58
src/main/java/org/lapaloma/aadd/cine/vo/Director.java
Normal file
58
src/main/java/org/lapaloma/aadd/cine/vo/Director.java
Normal file
@ -0,0 +1,58 @@
|
||||
package org.lapaloma.aadd.cine.vo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Entity
|
||||
@Table(name = "director")
|
||||
public class Director {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name="identificador")
|
||||
private Integer identificador;
|
||||
|
||||
@Column(name="nombre", length = 50)
|
||||
private String nombre;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "id_pais")
|
||||
private Pais pais;
|
||||
|
||||
@Column(name="fecha_nacimiento")
|
||||
private LocalDate fechaNacimiento;
|
||||
|
||||
public Integer getIdentificador() {
|
||||
return identificador;
|
||||
}
|
||||
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public Pais getPais() {
|
||||
return pais;
|
||||
}
|
||||
|
||||
public void setPais(Pais pais) {
|
||||
this.pais = pais;
|
||||
}
|
||||
|
||||
public LocalDate getFechaNacimiento() {
|
||||
return fechaNacimiento;
|
||||
}
|
||||
|
||||
public void setFechaNacimiento(LocalDate fechaNacimiento) {
|
||||
this.fechaNacimiento = fechaNacimiento;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Director [identificador=" + identificador + ", nombre=" + nombre + ", pais=" + pais
|
||||
+ ", fechaNacimiento=" + fechaNacimiento + "]\n";
|
||||
}
|
||||
}
|
||||
60
src/main/java/org/lapaloma/aadd/cine/vo/Pais.java
Normal file
60
src/main/java/org/lapaloma/aadd/cine/vo/Pais.java
Normal file
@ -0,0 +1,60 @@
|
||||
package org.lapaloma.aadd.cine.vo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "pais")
|
||||
public class Pais {
|
||||
@Id
|
||||
@Column(name = "identificador")
|
||||
private Integer identificador;
|
||||
|
||||
@Column(name = "nombre_pais" , length = 50)
|
||||
private String nombrePais;
|
||||
|
||||
@Column(name = "capital" , length = 20)
|
||||
private String capital;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "cod_continente")
|
||||
private Continente continente;
|
||||
|
||||
public Integer getIdentificador() {
|
||||
return identificador;
|
||||
}
|
||||
|
||||
public void setIdentificador(Integer identificador) {
|
||||
this.identificador = identificador;
|
||||
}
|
||||
|
||||
public String getNombrePais() {
|
||||
return nombrePais;
|
||||
}
|
||||
|
||||
public void setNombrePais(String nombrePais) {
|
||||
this.nombrePais = nombrePais;
|
||||
}
|
||||
|
||||
public String getCapital() {
|
||||
return capital;
|
||||
}
|
||||
|
||||
public void setCapital(String capital) {
|
||||
this.capital = capital;
|
||||
}
|
||||
|
||||
public Continente getContinente() {
|
||||
return continente;
|
||||
}
|
||||
|
||||
public void setContinente(Continente continente) {
|
||||
this.continente = continente;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Pais [identificador=" + identificador + ", nombrePais=" + nombrePais + ", capital=" + capital
|
||||
+ ", continente=" + continente + "]\n";
|
||||
}
|
||||
|
||||
}
|
||||
108
src/main/java/org/lapaloma/aadd/cine/vo/Pelicula.java
Normal file
108
src/main/java/org/lapaloma/aadd/cine/vo/Pelicula.java
Normal file
@ -0,0 +1,108 @@
|
||||
package org.lapaloma.aadd.cine.vo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "pelicula")
|
||||
public class Pelicula {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name="identificador")
|
||||
private Integer identificador;
|
||||
|
||||
@Column(name="titulo")
|
||||
private String titulo;
|
||||
|
||||
@Column(name="anyo", nullable = false)
|
||||
private Integer anyo;
|
||||
|
||||
@Column(name="idioma", length = 50)
|
||||
private String idioma;
|
||||
|
||||
@Column(name="color", columnDefinition = "boolean")
|
||||
private Boolean color;
|
||||
|
||||
@Column(name="observ")
|
||||
private String observacion;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "id_pais")
|
||||
private Pais paisLocalizacion;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "id_director", nullable = false)
|
||||
private Director director;
|
||||
|
||||
public Integer getIdentificador() {
|
||||
return identificador;
|
||||
}
|
||||
|
||||
public void setIdentificador(Integer identificador) {
|
||||
this.identificador = identificador;
|
||||
}
|
||||
|
||||
public String getTitulo() {
|
||||
return titulo;
|
||||
}
|
||||
|
||||
public void setTitulo(String titulo) {
|
||||
this.titulo = titulo;
|
||||
}
|
||||
|
||||
public Integer getAnyo() {
|
||||
return anyo;
|
||||
}
|
||||
|
||||
public void setAnyo(Integer anyo) {
|
||||
this.anyo = anyo;
|
||||
}
|
||||
|
||||
public String getIdioma() {
|
||||
return idioma;
|
||||
}
|
||||
|
||||
public void setIdioma(String idioma) {
|
||||
this.idioma = idioma;
|
||||
}
|
||||
|
||||
public Boolean getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Boolean color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String getObservacion() {
|
||||
return observacion;
|
||||
}
|
||||
|
||||
public void setObservacion(String observacion) {
|
||||
this.observacion = observacion;
|
||||
}
|
||||
|
||||
public Pais getPaisLocalizacion() {
|
||||
return paisLocalizacion;
|
||||
}
|
||||
|
||||
public void setPaisLocalizacion(Pais paisLocalizacion) {
|
||||
this.paisLocalizacion = paisLocalizacion;
|
||||
}
|
||||
|
||||
public Director getDirector() {
|
||||
return director;
|
||||
}
|
||||
|
||||
public void setDirector(Director director) {
|
||||
this.director = director;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Pelicula [identificador=" + identificador + ", titulo=" + titulo + ", anyo=" + anyo + ", idioma="
|
||||
+ idioma + ", color=" + color + ", observacion=" + observacion + ", paisLocalizacion="
|
||||
+ paisLocalizacion + ", director=" + director + "]\n";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
60
src/main/java/org/lapaloma/aadd/cine/vo/Reparto.java
Normal file
60
src/main/java/org/lapaloma/aadd/cine/vo/Reparto.java
Normal file
@ -0,0 +1,60 @@
|
||||
package org.lapaloma.aadd.cine.vo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "reparto")
|
||||
public class Reparto {
|
||||
|
||||
@EmbeddedId
|
||||
private RepartoId idReparto;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@MapsId("idActor") // Esto mapea a idActor en RepartoId
|
||||
@JoinColumn(name = "id_actor")
|
||||
private Actor actor;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@MapsId("idPelicula") // Esto mapea a idPelicula en RepartoId
|
||||
@JoinColumn(name = "id_pelicula")
|
||||
private Pelicula pelicula;
|
||||
|
||||
@Column(name = "personaje", length = 50, nullable = false)
|
||||
private String personaje;
|
||||
|
||||
public Actor getActor() {
|
||||
return actor;
|
||||
}
|
||||
|
||||
public void setActor(Actor actor) {
|
||||
this.actor = actor;
|
||||
}
|
||||
|
||||
public Pelicula getPelicula() {
|
||||
return pelicula;
|
||||
}
|
||||
|
||||
public void setPelicula(Pelicula pelicula) {
|
||||
this.pelicula = pelicula;
|
||||
}
|
||||
|
||||
public String getPersonaje() {
|
||||
return personaje;
|
||||
}
|
||||
|
||||
public void setPersonaje(String personaje) {
|
||||
this.personaje = personaje;
|
||||
}
|
||||
public RepartoId getIdReparto() {
|
||||
return idReparto;
|
||||
}
|
||||
|
||||
public void setIdReparto(RepartoId idReparto) {
|
||||
this.idReparto = idReparto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Reparto [actor=" + actor + ", pelicula=" + pelicula + ", personaje=" + personaje + "]\n";
|
||||
}
|
||||
}
|
||||
60
src/main/java/org/lapaloma/aadd/cine/vo/RepartoId.java
Normal file
60
src/main/java/org/lapaloma/aadd/cine/vo/RepartoId.java
Normal file
@ -0,0 +1,60 @@
|
||||
package org.lapaloma.aadd.cine.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
|
||||
|
||||
@Embeddable
|
||||
public class RepartoId implements Serializable {
|
||||
private static final long serialVersionUID = 6142631595518522640L;
|
||||
|
||||
@Column(name = "id_actor")
|
||||
private Integer idActor;
|
||||
|
||||
@Column(name = "id_pelicula")
|
||||
private Integer idPelicula;
|
||||
|
||||
public RepartoId() {
|
||||
}
|
||||
|
||||
public RepartoId(Integer idActor, Integer idPelicula) {
|
||||
this.idActor = idActor;
|
||||
this.idPelicula = idPelicula;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
RepartoId idReparto= (RepartoId) o;
|
||||
return Objects.equals(idActor, idReparto.idActor) && Objects.equals(idPelicula, idReparto.idPelicula);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(idActor, idPelicula);
|
||||
}
|
||||
|
||||
public Integer getIdActor() {
|
||||
return idActor;
|
||||
}
|
||||
|
||||
public void setIdActor(Integer idActor) {
|
||||
this.idActor = idActor;
|
||||
}
|
||||
|
||||
public Integer getIdPelicula() {
|
||||
return idPelicula;
|
||||
}
|
||||
|
||||
public void setIdPelicula(Integer idPelicula) {
|
||||
this.idPelicula = idPelicula;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RepartoId [idActor=" + idActor + ", idPelicula=" + idPelicula + "]";
|
||||
}
|
||||
|
||||
}
|
||||
27
src/main/resources/hibernate.cfg.xml
Normal file
27
src/main/resources/hibernate.cfg.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="connection.url">jdbc:mysql://192.168.1.36:3306/Cine</property>
|
||||
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
|
||||
|
||||
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
||||
|
||||
<property name="connection.username">root</property>
|
||||
<property name="connection.password">mysql_123</property>
|
||||
|
||||
<!-- DB schema will be updated if needed -->
|
||||
<property name="hbm2ddl.auto">none</property>
|
||||
<property name="show_sql">false</property>
|
||||
<property name="format_sql">flase</property>
|
||||
|
||||
<mapping class="org.lapaloma.aadd.cine.vo.Continente"></mapping>
|
||||
<mapping class="org.lapaloma.aadd.cine.vo.Pais"></mapping>
|
||||
<mapping class="org.lapaloma.aadd.cine.vo.Director"></mapping>
|
||||
<mapping class="org.lapaloma.aadd.cine.vo.Pelicula"></mapping>
|
||||
<mapping class="org.lapaloma.aadd.cine.vo.Actor"></mapping>
|
||||
<mapping class="org.lapaloma.aadd.cine.vo.Reparto"></mapping>
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
Loading…
Reference in New Issue
Block a user