marcelofoxes

Estado.java

May 20th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1. package com.zxsheart.pedidovenda.model.endereco;
  2.  
  3. import java.io.Serializable;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. import javax.persistence.CascadeType;
  8. import javax.persistence.Column;
  9. import javax.persistence.Entity;
  10. import javax.persistence.GeneratedValue;
  11. import javax.persistence.GenerationType;
  12. import javax.persistence.Id;
  13. import javax.persistence.OneToMany;
  14. import javax.validation.constraints.NotNull;
  15.  
  16. @Entity
  17. public class Estado implements Serializable {
  18.     private static final long serialVersionUID = 2L;
  19.     private Long codigo;
  20.     private String sigla;
  21.     private String nome;
  22.     private List<Cidade> cidades = new ArrayList<>();
  23.    
  24.     /**
  25.      * Acessor de leitura para o campo codigo
  26.      * @return o codigo
  27.      */
  28.     @Id
  29.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  30.     public Long getCodigo() {
  31.         return codigo;
  32.     }
  33.  
  34.     /**
  35.      * Define um novo valor para o campo codigo
  36.      * @param codigo o codigo a ser definido
  37.      */
  38.     public void setCodigo(Long codigo) {
  39.         this.codigo = codigo;
  40.     }
  41.    
  42.     @NotNull
  43.     @Column(length = 2)
  44.     public String getSigla() {
  45.         return sigla;
  46.     }
  47.  
  48.     public void setSigla(String sigla) {
  49.         this.sigla = sigla;
  50.     }
  51.    
  52.     @Column(nullable = false, length = 50)
  53.     public String getNome() {
  54.         return nome;
  55.     }
  56.  
  57.     public void setNome(String nome) {
  58.         this.nome = nome;
  59.     }
  60.  
  61.     @OneToMany(cascade=CascadeType.ALL, orphanRemoval=true, mappedBy="estado")
  62.     public List<Cidade> getCidades() {
  63.         return cidades;
  64.     }
  65.  
  66.     public void setCidades(List<Cidade> cidades) {
  67.         this.cidades = cidades;
  68.     }
  69.  
  70.     @Override
  71.     public int hashCode() {
  72.         final int prime = 31;
  73.         int result = 1;
  74.         result = prime * result + ((sigla == null) ? 0 : sigla.hashCode());
  75.         return result;
  76.     }
  77.  
  78.     @Override
  79.     public boolean equals(Object obj) {
  80.         if (this == obj)
  81.             return true;
  82.         if (obj == null)
  83.             return false;
  84.         if (!(obj instanceof Estado))
  85.             return false;
  86.         Estado other = (Estado) obj;
  87.         if (sigla == null) {
  88.             if (other.sigla != null)
  89.                 return false;
  90.         } else if (!sigla.equals(other.sigla))
  91.             return false;
  92.         return true;
  93.     }  
  94.  
  95.    
  96. }
Add Comment
Please, Sign In to add comment