Olá Pessoal,
gostaria de saber o seguinte:
tem como no hibernate gerar generators e triggers diretamente, como as tabelas?
usando o postgres eu cria os ID como serial é um auto incremento. da pra faze isso no hibernate???
falow
Olá Pessoal,
gostaria de saber o seguinte:
tem como no hibernate gerar generators e triggers diretamente, como as tabelas?
usando o postgres eu cria os ID como serial é um auto incremento. da pra faze isso no hibernate???
falow
Bom aqui eu faço assim:
package br.gov.nutec.modelo;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
@Entity
@Table(name="pessoa")
public class Pessoa implements Serializable {
private static long serialVersionUID = 2174678509151116408L;
public static long getSerialVersionUID() {
return serialVersionUID;
}
public static void setSerialVersionUID(long aSerialVersionUID) {
serialVersionUID = aSerialVersionUID;
}
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="pessoa_id") // chave primaria
private Long id;
@NotNull
@Length(min =5 , max = 40)
@Column(name="nome")
private String nome;
@Column(name="cpf")
private Long cpf;
@Column(name="matricula")
private String matricula;
@Column(name="digina")
private String digina;
@Column(name="data_matricula")
@Temporal(javax.persistence.TemporalType.DATE)
private Date data_matricula;
@Column(name="RG")
private String RG;
@Column(name="orgao_exp")
private String orgao_exp;
@Column(name="titulo_ele")
private String titulo_ele;
@Column(name="endereco")
private String endereco;
@Column(name="bairro")
private String bairro;
@Column(name="cidade")
private String cidade;
@Column(name="uf")
private String uf;
@Column(name="fone")
private String fone;
@Column(name="celular")
private String celular;
@Column(name="email")
private String email;
@Column(name="senha")
private String senha;
@Temporal(TemporalType.DATE)
@Column(name="data_nasc")
private Date data_nasc;
public void setNome(String nome) {
System.out.println("Pessoa >> nome : " + this.nome);
this.nome = nome;
}
@Override
public boolean equals(Object obj){
if( (obj instanceof Pessoa) && ( ((Pessoa)obj).getCpf().equals(this.getCpf())) ){
return true;
}else{
return false;
}
}
@Override
public int hashCode() {
int hash = 3;
hash = 23 * hash + (this.getId() != null ? this.getId().hashCode() : 0);
hash = 23 * hash + (this.getNome() != null ? this.getNome().hashCode() : 0);
hash = 23 * hash + (this.getCpf() != null ? this.getCpf().hashCode() : 0);
hash = 23 * hash + (this.getMatricula() != null ? this.getMatricula().hashCode() : 0);
hash = 23 * hash + (this.getDigina() != null ? this.getDigina().hashCode() : 0);
hash = 23 * hash + (this.getData_matricula() != null ? this.getData_matricula().hashCode() : 0);
hash = 23 * hash + (this.getRG() != null ? this.getRG().hashCode() : 0);
hash = 23 * hash + (this.getOrgao_exp() != null ? this.getOrgao_exp().hashCode() : 0);
hash = 23 * hash + (this.getTitulo_ele() != null ? this.getTitulo_ele().hashCode() : 0);
hash = 23 * hash + (this.getEndereco() != null ? this.getEndereco().hashCode() : 0);
hash = 23 * hash + (this.getBairro() != null ? this.getBairro().hashCode() : 0);
hash = 23 * hash + (this.getCidade() != null ? this.getCidade().hashCode() : 0);
hash = 23 * hash + (this.getUf() != null ? this.getUf().hashCode() : 0);
hash = 23 * hash + (this.getFone() != null ? this.getFone().hashCode() : 0);
hash = 23 * hash + (this.getCelular() != null ? this.getCelular().hashCode() : 0);
hash = 23 * hash + (this.getEmail() != null ? this.getEmail().hashCode() : 0);
hash = 23 * hash + (this.getSenha() != null ? this.getSenha().hashCode() : 0);
hash = 23 * hash + (this.getData_nasc() != null ? this.getData_nasc().hashCode() : 0);
return hash;
}
/**
* @return the id
*/
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the nome
*/
public String getNome() {
return nome;
}
/**
* @return the cpf
*/
public Long getCpf() {
return cpf;
}
/**
* @param cpf the cpf to set
*/
public void setCpf(Long cpf) {
this.cpf = cpf;
}
/**
* @return the matricula
*/
public String getMatricula() {
return matricula;
}
/**
* @param matricula the matricula to set
*/
public void setMatricula(String matricula) {
this.matricula = matricula;
}
/**
* @return the digina
*/
public String getDigina() {
return digina;
}
/**
* @param digina the digina to set
*/
public void setDigina(String digina) {
this.digina = digina;
}
/**
* @return the data_matricula
*/
public Date getData_matricula() {
return data_matricula;
}
/**
* @param data_matricula the data_matricula to set
*/
public void setData_matricula(Date data_matricula) {
this.data_matricula = data_matricula;
}
/**
* @return the RG
*/
public String getRG() {
return RG;
}
/**
* @param RG the RG to set
*/
public void setRG(String RG) {
this.RG = RG;
}
/**
* @return the orgao_exp
*/
public String getOrgao_exp() {
return orgao_exp;
}
/**
* @param orgao_exp the orgao_exp to set
*/
public void setOrgao_exp(String orgao_exp) {
this.orgao_exp = orgao_exp;
}
/**
* @return the titulo_ele
*/
public String getTitulo_ele() {
return titulo_ele;
}
/**
* @param titulo_ele the titulo_ele to set
*/
public void setTitulo_ele(String titulo_ele) {
this.titulo_ele = titulo_ele;
}
/**
* @return the endereco
*/
public String getEndereco() {
return endereco;
}
/**
* @param endereco the endereco to set
*/
public void setEndereco(String endereco) {
this.endereco = endereco;
}
/**
* @return the bairro
*/
public String getBairro() {
return bairro;
}
/**
* @param bairro the bairro to set
*/
public void setBairro(String bairro) {
this.bairro = bairro;
}
/**
* @return the cidade
*/
public String getCidade() {
return cidade;
}
/**
* @param cidade the cidade to set
*/
public void setCidade(String cidade) {
this.cidade = cidade;
}
/**
* @return the uf
*/
public String getUf() {
return uf;
}
/**
* @param uf the uf to set
*/
public void setUf(String uf) {
this.uf = uf;
}
/**
* @return the fone
*/
public String getFone() {
return fone;
}
/**
* @param fone the fone to set
*/
public void setFone(String fone) {
this.fone = fone;
}
/**
* @return the celular
*/
public String getCelular() {
return celular;
}
/**
* @param celular the celular to set
*/
public void setCelular(String celular) {
this.celular = celular;
}
/**
* @return the email
*/
public String getEmail() {
return email;
}
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
/**
* @return the senha
*/
public String getSenha() {
return senha;
}
/**
* @param senha the senha to set
*/
public void setSenha(String senha) {
this.senha = senha;
}
/**
* @return the data_nasc
*/
public Date getData_nasc() {
return data_nasc;
}
/**
* @param data_nasc the data_nasc to set
*/
public void setData_nasc(Date data_nasc) {
this.data_nasc = data_nasc;
}
}