@author Jorge
*/
@Entity()
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = “PESSOA”)
public class Pessoa implements Serializable {
@Id
@Column(name = “ID”)
@SequenceGenerator(name = “SEQ”, sequenceName = “GEN_PESSOA”, allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = “SEQ”)
private Integer id;
@Column(name = “NOME”, length = 50, nullable = false)
private String nome;
@Column(name = “ENDERECO”, length = 40)
private String endereco;
@Column(name = “BAIRRO”, length = 25)
private String bairro;
@Column(name = “CEP”, length = 9)
private String cep;
@Column(name = “NEWSLETTER”, length = 1)
private Character newsletter;
@Column(name = “CLIENTE”, length = 1, nullable = false)
private Character cliente;
@Column(name = “FORNECEDOR”, length = 1, nullable = false)
private Character fornecedor;
@Column(name = “DATACADASTRO”)
@Temporal(TemporalType.TIMESTAMP)
private Calendar dataCadastro;
@Column(name = “TIPO”, length = 1, nullable = false)
private Character tipo;
@ManyToOne
@JoinColumn(name = “CIDADE”, referencedColumnName = “ID”)
private Cidade cidade;
@OneToMany(mappedBy = “pessoa”, cascade = {CascadeType.ALL})
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@LazyCollection(LazyCollectionOption.FALSE)
private Collection contatosCollection = new ArrayList();
@OneToMany(mappedBy = “pessoa”, cascade = {CascadeType.ALL})
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@LazyCollection(LazyCollectionOption.FALSE)
private Collection telefonesCollection = new ArrayList();
public Pessoa() {
}
public Pessoa(Integer id, String nome, Character cliente, Character fornecedor, Character tipo) {
this.id = id;
this.nome = nome;
this.cliente = cliente;
this.fornecedor = fornecedor;
this.tipo = tipo;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public String getBairro() {
return bairro;
}
public void setBairro(String bairro) {
this.bairro = bairro;
}
public String getCep() {
return cep;
}
public void setCep(String cep) {
this.cep = cep;
}
public Character getNewsletter() {
return newsletter;
}
public void setNewsletter(Character newsletter) {
this.newsletter = newsletter;
}
public Character getCliente() {
return cliente;
}
public void setCliente(Character cliente) {
this.cliente = cliente;
}
public Character getFornecedor() {
return fornecedor;
}
public void setFornecedor(Character fornecedor) {
this.fornecedor = fornecedor;
}
public Calendar getDataCadastro() {
return dataCadastro;
}
public void setDataCadastro(Calendar dataCadastro) {
this.dataCadastro = dataCadastro;
}
public Character getTipo() {
return tipo;
}
public void setTipo(Character tipo) {
this.tipo = tipo;
}
@Override
public String toString() {
return getNome();
}
public Cidade getCidade() {
return cidade;
}
public void setCidade(Cidade cidade) {
this.cidade = cidade;
}
public Collection getContatosCollection() {
return contatosCollection;
}
public void setContatosCollection(List contatosCollection) {
this.contatosCollection = contatosCollection;
}
public void adicionarContato(ContatosPessoa con) {
con.setPessoa(this);
// if (!getContatosCollection().contains(con)) {
getContatosCollection().add(con);
// }
}
public void removerContato(ContatosPessoa con) {
if (getContatosCollection().contains(con)) {
getContatosCollection().remove(con);
}
}
public void removerTodosContatos() {
getContatosCollection().clear();
}
public Iterator getIteratorContatos() {
return getContatosCollection().iterator();
}
public Collection getTelefonesCollection() {
return telefonesCollection;
}
public void setTelefonesCollection(List telefonesCollection) {
this.telefonesCollection = telefonesCollection;
}
public void adicionarTelefone(TelefonesPessoa tel) {
tel.setPessoa(this);
if (!getTelefonesCollection().contains(tel)) {
getTelefonesCollection().add(tel);
}
}
public void removerTelefone(TelefonesPessoa tel) {
if (getTelefonesCollection().contains(tel)) {
getTelefonesCollection().remove(tel);
}
}
public void removerTodosTelefones() {
getTelefonesCollection().clear();
}
public Iterator getIteratorTelefones() {
return getTelefonesCollection().iterator();
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Pessoa other = (Pessoa) obj;
if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 3;
hash = 67 * hash + (this.id != null ? this.id.hashCode() : 0);
return hash;
}