marcelofoxes

Cidade.java

May 20th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. package com.zxsheart.pedidovenda.model.endereco;
  2.  
  3. import java.io.Serializable;
  4.  
  5. import javax.persistence.CascadeType;
  6. import javax.persistence.Column;
  7. import javax.persistence.Entity;
  8. import javax.persistence.ForeignKey;
  9. import javax.persistence.GeneratedValue;
  10. import javax.persistence.GenerationType;
  11. import javax.persistence.Id;
  12. import javax.persistence.JoinColumn;
  13. import javax.persistence.ManyToOne;
  14. import javax.validation.constraints.NotNull;
  15. import javax.validation.constraints.Size;
  16.  
  17. import org.hibernate.validator.constraints.NotBlank;
  18.  
  19. @Entity
  20. public class Cidade implements Serializable {
  21.     private static final long serialVersionUID = 1L;
  22.     private Integer codigo;
  23.     private String nome;
  24.     private Estado estado;
  25.  
  26.     @Id
  27.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  28.     public Integer getCodigo() {
  29.         return codigo;
  30.     }
  31.  
  32.     public void setCodigo(Integer codigo) {
  33.         this.codigo = codigo;
  34.     }
  35.  
  36.     @NotBlank
  37.     @Size(min = 3, max = 50)
  38.     @Column(nullable = false, length = 50)
  39.     public String getNome() {
  40.         return nome;
  41.     }
  42.  
  43.     public void setNome(String nome) {
  44.         this.nome = nome;
  45.     }
  46.  
  47.     @NotNull
  48.     @ManyToOne(cascade = CascadeType.PERSIST, optional = false)
  49.     @JoinColumn(name = "estado_codigo", nullable = false, foreignKey = @ForeignKey(name = "fk_cidade_to_estado"))
  50.     public Estado getEstado() {
  51.         return estado;
  52.     }
  53.  
  54.     public void setEstado(Estado estado) {
  55.         this.estado = estado;
  56.     }
  57.  
  58.     @Override
  59.     public int hashCode() {
  60.         final int prime = 31;
  61.         int result = 1;
  62.         result = prime * result + ((codigo == null) ? 0 : codigo.hashCode());
  63.         return result;
  64.     }
  65.  
  66.     @Override
  67.     public boolean equals(Object obj) {
  68.         if (this == obj)
  69.             return true;
  70.         if (obj == null)
  71.             return false;
  72.         if (!(obj instanceof Cidade))
  73.             return false;
  74.         Cidade other = (Cidade) obj;
  75.         if (codigo == null) {
  76.             if (other.codigo != null)
  77.                 return false;
  78.         } else if (!codigo.equals(other.codigo))
  79.             return false;
  80.         return true;
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment