mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/tutorialjava2024-25.git
synced 2025-11-10 02:13:07 +01:00
feat(ch 8 & 9): added
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.*;
|
||||
|
||||
import tutorialJava.modelosBasesDeDatosComunesJPA.Entidad;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* The persistent class for the provincia database table.
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="provincia")
|
||||
@NamedQuery(name="Provincia.findAll", query="SELECT p FROM Provincia p")
|
||||
public class Provincia extends Entidad implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
private String descripcion;
|
||||
|
||||
//bi-directional many-to-one association to Persona
|
||||
@OneToMany(mappedBy="provincia")
|
||||
private List<Persona> personas;
|
||||
|
||||
public Provincia() {
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescripcion() {
|
||||
return this.descripcion;
|
||||
}
|
||||
|
||||
public void setDescripcion(String descripcion) {
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
|
||||
public List<Persona> getPersonas() {
|
||||
return this.personas;
|
||||
}
|
||||
|
||||
public void setPersonas(List<Persona> personas) {
|
||||
this.personas = personas;
|
||||
}
|
||||
|
||||
public Persona addPersona(Persona persona) {
|
||||
getPersonas().add(persona);
|
||||
persona.setProvincia(this);
|
||||
|
||||
return persona;
|
||||
}
|
||||
|
||||
public Persona removePersona(Persona persona) {
|
||||
getPersonas().remove(persona);
|
||||
persona.setProvincia(null);
|
||||
|
||||
return persona;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.descripcion;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user