Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TABELLA DELLE CITTA'
- package corso.java.model;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.Table;
- @Entity // promuove la classe ad entità del data layer
- @Table(name="cities") // descrive le caratteristiche della tabella che rappresenta la classe
- public class City {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO) // sarà il database a gestire il valore
- private Long id;
- @Column // promuove l'attributo della classe in colonna della tabella
- private String name;
- // il campo fiscalCode rappresenta UNA chiave della tabella
- @Column(length = 4)
- private String fiscalCode;
- @Column
- private Long people;
- private Province province;
- private Region region;
- // Getters
- public String getName() {
- return name;
- }
- public String getFiscalCode() {
- return fiscalCode;
- }
- public Long getPeople() {
- return people;
- }
- public Province getProvince() {
- return province;
- }
- public Region getRegion() {
- return region;
- }
- // Setters
- public void setName(String name) {
- this.name = name;
- }
- public void setFiscalCode(String fiscalCode) {
- this.fiscalCode = fiscalCode;
- }
- public void setPeople(Long people) {
- this.people = people;
- }
- public void setProvince(Province province) {
- this.province = province;
- }
- public void setRegion(Region region) {
- this.region = region;
- }
- // Metodi di supporto da Object
- @Override
- public int hashCode() {
- return fiscalCode.hashCode();
- }
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof City)
- return hashCode() == obj.hashCode();
- return super.equals(obj);
- }
- @Override
- public String toString() {
- return String.format("%s (%s)", name, province.getAcronym());
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- }
- // TABELLA DELLE PROVINCE
- package corso.java.model;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.Table;
- @Entity
- @Table(name = "provinces")
- public class Province {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO) // sarà il database a gestire il valore
- private Long id;
- @Column
- private String acronym;
- @Column
- private String name;
- public String getAcronym() {
- return acronym;
- }
- public String getName() {
- return name;
- }
- public void setAcronym(String acronym) {
- this.acronym = acronym;
- }
- public void setName(String name) {
- this.name = name;
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- }
- // TABELLA DELLE REGIONI
- package corso.java.model;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.Table;
- @Entity
- @Table(name = "regions")
- public class Region {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO) // sarà il database a gestire il valore
- private Long id;
- @Column
- private String name;
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement