Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.zxsheart.pedidovenda.model.endereco;
- import java.io.Serializable;
- import javax.persistence.CascadeType;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.ForeignKey;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.ManyToOne;
- import javax.validation.constraints.NotNull;
- import javax.validation.constraints.Size;
- import org.hibernate.validator.constraints.NotBlank;
- @Entity
- public class Cidade implements Serializable {
- private static final long serialVersionUID = 1L;
- private Integer codigo;
- private String nome;
- private Estado estado;
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- public Integer getCodigo() {
- return codigo;
- }
- public void setCodigo(Integer codigo) {
- this.codigo = codigo;
- }
- @NotBlank
- @Size(min = 3, max = 50)
- @Column(nullable = false, length = 50)
- public String getNome() {
- return nome;
- }
- public void setNome(String nome) {
- this.nome = nome;
- }
- @NotNull
- @ManyToOne(cascade = CascadeType.PERSIST, optional = false)
- @JoinColumn(name = "estado_codigo", nullable = false, foreignKey = @ForeignKey(name = "fk_cidade_to_estado"))
- public Estado getEstado() {
- return estado;
- }
- public void setEstado(Estado estado) {
- this.estado = estado;
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((codigo == null) ? 0 : codigo.hashCode());
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof Cidade))
- return false;
- Cidade other = (Cidade) obj;
- if (codigo == null) {
- if (other.codigo != null)
- return false;
- } else if (!codigo.equals(other.codigo))
- return false;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment