Senhores,
Estou criando um software com 6 entidades: Fiador, Locatario, Locador, Imobiliaria, Procurador e Imovel.
Todos estou utilizando alto incremento e atribuindo o nome de Id a todos (Creio que este deve ser meu erro), de fato oque esta ocorrendo é que no banco os Id’s nao estão sendo separados exemplo: Cadastro um Locador o ID atribuido é 1 correto?, quando eu vou Cadastrar a Imobiliaria inves de ser atribuido o ID 1 é atribuido o ID 2, e quando eu vou a cadastrar um Locaodr i Id atribui é 3, deu para entede??
Minha duvida é esta espero que ajude, vou posta o código de uma entidade só apra vocês verem.
package imobil.Entidades;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
@Entity
public class Imovel implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(length=20, nullable=false)
@Temporal(javax.persistence.TemporalType.DATE)
private Date datamatricula_imovel;
@Column(length=20, nullable=false)
private String finalidade_imovel;
@Column(length=20, nullable=false)
private String tipo_imovel;
@Column(length=100, nullable=false)
private String endereco_imovel;
@Column(length=40, nullable=false)
private String estado_imovel;
@Column(length=90, nullable=false)
private String cidade_imovel;
@Column(length=30)
private String bairro_imovel;
@Column(length=100)
private String complemento_imovel;
@Column(length=250)
private String descricao_imovel;
@ManyToOne
private Locador locador;
public Imovel() {
}
public Imovel(Long id, Date datamatricula_imovel, String finalidade_imovel, String tipo_imovel, String endereco_imovel, String estado_imovel, String cidade_imovel, String bairro_imovel, String complemento_imovel, String descricao_imovel, Locador locador) {
this.id = id;
this.datamatricula_imovel = datamatricula_imovel;
this.finalidade_imovel = finalidade_imovel;
this.tipo_imovel = tipo_imovel;
this.endereco_imovel = endereco_imovel;
this.estado_imovel = estado_imovel;
this.cidade_imovel = cidade_imovel;
this.bairro_imovel = bairro_imovel;
this.complemento_imovel = complemento_imovel;
this.descricao_imovel = descricao_imovel;
this.locador = locador;
}
public String getBairro_imovel() {
return bairro_imovel;
}
public void setBairro_imovel(String bairro_imovel) {
this.bairro_imovel = bairro_imovel;
}
public String getCidade_imovel() {
return cidade_imovel;
}
public void setCidade_imovel(String cidade_imovel) {
this.cidade_imovel = cidade_imovel;
}
public String getComplemento_imovel() {
return complemento_imovel;
}
public void setComplemento_imovel(String complemento_imovel) {
this.complemento_imovel = complemento_imovel;
}
public Date getDatamatricula_imovel() {
return datamatricula_imovel;
}
public void setDatamatricula_imovel(Date datamatricula_imovel) {
this.datamatricula_imovel = datamatricula_imovel;
}
public String getDescricao_imovel() {
return descricao_imovel;
}
public void setDescricao_imovel(String descricao_imovel) {
this.descricao_imovel = descricao_imovel;
}
public String getEndereco_imovel() {
return endereco_imovel;
}
public void setEndereco_imovel(String endereco_imovel) {
this.endereco_imovel = endereco_imovel;
}
public String getEstado_imovel() {
return estado_imovel;
}
public void setEstado_imovel(String estado_imovel) {
this.estado_imovel = estado_imovel;
}
public String getFinalidade_imovel() {
return finalidade_imovel;
}
public void setFinalidade_imovel(String finalidade_imovel) {
this.finalidade_imovel = finalidade_imovel;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Locador getLocador() {
return locador;
}
public void setLocador(Locador locador) {
this.locador = locador;
}
public String getTipo_imovel() {
return tipo_imovel;
}
public void setTipo_imovel(String tipo_imovel) {
this.tipo_imovel = tipo_imovel;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Imovel)) {
return false;
}
Imovel other = (Imovel) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "imobil.Entidades.Imovel[id=" + id + "]";
}
}